How can I plot phase and magnitude of Fourier transform of a 2D image in MATLAB?
I am using angle
and abs
and then use imshow
, but I get a black image.
what is the use of fftshift
in this plotting?
Asked
Active
Viewed 5,343 times
2

Luis Mendo
- 110,752
- 13
- 76
- 147

amanda
- 33
- 1
- 7
-
try imagesc(abs(fftshift(fft2(I)))); – lennon310 Mar 06 '14 at 20:36
-
I tried this but it only display a black image with a white point in the center. – amanda Mar 07 '14 at 06:05
2 Answers
1
F = fft2(I); where I is the input
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
Try this. Code taken from:How to plot a 2D FFT in Matlab?
-
I've seen this gode but I didn't understand why we use log and fftshift why we didn't just show that without using this? – amanda Mar 07 '14 at 05:57
-
Thanks lakesh you saved me! I've spent Hours searching for that log(F+1) :D Here is a clarification to be in safe side when you prepare the input I if you read it by f = imread(imPath); you will need this F = fft2(double(f)); as the image has been read in unit8 format so they should be converted to double arrays before doing the FFTs. Quoted from http://matlabgeeks.com/tips-tutorials/how-to-do-a-2-d-fourier-transform-in-matlab/#comment-5137 – N0rA Jul 02 '14 at 15:33
1
From your comment, you need to remove the DC offset. Something like:
imagesc(abs(fftshift(fft2(I - mean(I(:))))));

ChuNan
- 1,131
- 2
- 11
- 27