How to plot a 2D FFT in Matlab?

Yoav picture Yoav · Nov 25, 2012 · Viewed 114.1k times · Source

I am using fft2 to compute the Fourier Transform of a grayscale image in MATLAB.

What is the common way to plot the magnitude of the result?

Answer

Yoav picture Yoav · Nov 25, 2012

Assuming that I is your input image and F is its Fourier Transform (i.e. F = fft2(I))

You can use this code:

F = fftshift(F); % Center FFT

F = abs(F); % Get the magnitude
F = log(F+1); % Use log, for perceptual scaling, and +1 since log(0) is undefined
F = mat2gray(F); % Use mat2gray to scale the image between 0 and 1

imshow(F,[]); % Display the result