Skip to content

Commit

Permalink
fast fourier transform
Browse files Browse the repository at this point in the history
  • Loading branch information
susantabiswas committed Nov 12, 2017
1 parent eb85c68 commit cfdcc61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Day4/fast_fourier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
''' Do fast fourier transform on an image '''

import cv2
import numpy as np

img = cv2.imread('lenna.jpg', 0)
rows, cols = img.shape

#convert to frequency domain
f = np.fft.fft2(img)
#bring the dc component( 0 freq) to the center by
#shifting by n/2 in both directions
fshift = np.fft.fftshift(f)
magnitude_spectrum = 20 * np.log( np.abs(fshift) )

cv2.imwrite('fft.jpg', magnitude_spectrum)

''' ## inverse fft
crow = rows / 2
ccol = cols / 2
fshift[crow - 30:crow + 30, ccol - 30:ccol + 30] = 0
f_ishift = np.fft.ifftshift(fshift)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)
cv2.imwrite('orignal_fft.jpg', img_back)
'''
Binary file added Day4/fft.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cfdcc61

Please sign in to comment.