Basj
Basj

Reputation: 46463

Plot the 2D FFT of an image

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?

Upvotes: 9

Views: 37501

Answers (1)

Aguy
Aguy

Reputation: 8059

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))

Upvotes: 13

Related Questions