# Understanding FFT output in Matlab

I'm very new to Fourier transform and I want to plot the Fourier transform of an image in Matlab. I've seen many examples and in all of them, the fft() of the image is a black picture with some white parts in the center. But when I plot the fft() I get these pictures:

This is my code:

clear all;

figure("Name",'Image');
imshow(img)

F = fft(img);
figure("Name",'Fimage');
imshow(F)


Is it OK? Or there is something wrong with it?

I'm very new to Fourier transform

I suggest to start with the math here. Make sure you understand the formula and WHY it is the way it is. Then work your way up by doing simple examples where you write the code AND also calculate the result by hand so you can compare the two and get a feel of how the code works

1. Start with a single non-zero pixel in the middle.
2. Move the the pixel to different locations. See what happens. Remember to look both at the phase and the magnitude.
3. Do a horizonal line
4. Do a vertical line
5. Shift and rotate a line
6. Do 2 or 3 individual pixels
7. Modulate the intensity of the pixels
8. Do a line that has a gray scale

Keep doing this until you can reliable produce the same result in code and by hand. Then you can move to actual images and see if the intuition that you have developed so far is useful.

You should try something like:

F = fft2(img);
figure; imagesc(abs(F));


In image processing many times we're after the Log Spectrum:

F = fft2(img);
figure; imagesc(log10(1 + abs(F)));

• Why do we use abs?
– Mina
Commented Dec 31, 2021 at 10:54
• And what is the different between fft and fft2? Should we use fft2 for images?
– Mina
Commented Dec 31, 2021 at 10:54
• Yes, you should fft2 for images. it's the difference between a 1-dimensional and 2-dimensional Fourier Transform Commented Dec 31, 2021 at 13:14
• @Mina, the output of the Fourier transform for any dimensionality (e.g. 1D, 2D) outputs complex values. The absolute value gives you the magnitude of the Fourier transform. In MATLAB, the angle() function can be used to get the phase information with unity magnitude. The code in the original question would likely only plot the real part of the Fourier transform.
– Ash
Commented Jan 21, 2022 at 0:40
Y = fft2(x);
imagesc(10*log10(abs(fftshift(Y))));