I'm trying to plot the 2D FFT of an image:
from scipy import fftpack, ndimage
import matplotlib.pyplot as plt
image = ndimage.imread('image2.jpg', flatten=True) # flatten=True gives a greyscale image
fft2 = fftpack.fft2(image)
plt.imshow(fft2)
plt.show()
But I get TypeError: Image data can not convert to float
.
How to plot the 2D FFT of an image?
Y = fft2( X ) returns the two-dimensional Fourier transform of a matrix using a fast Fourier transform algorithm, which is equivalent to computing fft(fft(X). '). ' . If X is a multidimensional array, then fft2 takes the 2-D transform of each dimension higher than 2.
S = fftshift( fftshift(F), 2 ); as otherwise you only move the origin to the center of an edge rather than to the center of the array.
2D FFT (2-dimensional Fast Fourier Transform) can be used to analyze the frequency spectrum of 2D signal (matrix) data. Conversely, 2D IFFT (2-dimension Inverse Fast Fourier Transform) is able to reconstruct a 2D signal from a 2D frequency spectrum.
The result of any fft is generally composed of complex numbers. That is why you can't plot it this way. Depending on what you're looking for you can start with looking at the absolute value
plt.imshow(abs(fft2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With