Yuseferi
Yuseferi

Reputation: 8670

Fourier transform of image in magnitude not working

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 : enter image description here

Where is the problem?

Upvotes: 0

Views: 506

Answers (1)

anandr
anandr

Reputation: 1662

Two things here.

  1. Input image for 2D FFT should be intensity image (or grayscale), which is mxnx1 in size, not RGB, which is mxnx3 in size.

  2. 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

Related Questions