Reputation: 8670
I want to plot magnitude and phase of the Fourier transform of an image in matlab. I implemented the tutorial I read in this link line by line but for magnitude, only a white screen is plotted.
My code:
I=imread('16.jpg');
fftA = fft2(double(I));
figure, imshow(abs(fftshift(fftA)));
title('Image FFT2 Magnitude');
figure, imshow(angle(fftshift(fftA)),[-pi pi]);
title('Image FFT2 Phase')
My original image is :
Where is the problem?
Upvotes: 0
Views: 506
Reputation: 1662
Two things here.
Input image for 2D FFT should be intensity image (or grayscale), which is mxnx1 in size, not RGB, which is mxnx3 in size.
If image matrix is of class double
, its intensity is expected to be in [0,1] range. Values greater than 1 will be shown as 1 (filled with highest color of figure colormap).
To convert RGB image to grayscale use rgb2gray
:
Irgb = imread('16.jpg');
Igray = rgb2gray(Irgb);
To solve latter rescale your image or use imagesc
combined with axis equal
to preserve scale:
figure;
imagesc(abs(fftshift(fftA))); axis equal; axis tight;
Upvotes: 2