Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 789
Basj Avatar asked Jul 12 '16 15:07

Basj


People also ask

How do you do 2D FFT?

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.

How do I display the FFT of an image in Matlab?

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.

What does a 2D FFT show?

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.


1 Answers

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))
like image 163
Aguy Avatar answered Oct 07 '22 02:10

Aguy