The FFT with the scipy.fftpack module

We'll use the scipy.fftpack module's fft2()/ifft2() function to compute the DFT/IDFT with the FFT algorithm using a grayscale image, rhino.jpg:

im = np.array(Image.open('../images/rhino.jpg').convert('L')) # we shall work with grayscale imagesnr = signaltonoise(im, axis=None)print('SNR for the original image = ' + str(snr))# SNR for the original image = 2.023722773801701# now call FFT and IFFTfreq = fp.fft2(im)im1 = fp.ifft2(freq).realsnr = signaltonoise(im1, axis=None)print('SNR for the image obtained after reconstruction = ' + str(snr))# SNR for the image obtained after reconstruction = 2.0237227738013224assert(np.allclose(im, im1)) # make sure the forward and inverse FFT are close to each otherpylab.figure(figsize=(20,10)) ...

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.