2
$\begingroup$

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

This is my code:

clear all;

img = rgb2gray(imread('images.jpg'));
figure("Name",'Image');
imshow(img)


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

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

$\endgroup$

3 Answers 3

1
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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)));
$\endgroup$
4
  • $\begingroup$ Why do we use abs? $\endgroup$
    – Mina
    Commented Dec 31, 2021 at 10:54
  • $\begingroup$ And what is the different between fft and fft2? Should we use fft2 for images? $\endgroup$
    – Mina
    Commented Dec 31, 2021 at 10:54
  • $\begingroup$ Yes, you should fft2 for images. it's the difference between a 1-dimensional and 2-dimensional Fourier Transform $\endgroup$
    – Hilmar
    Commented Dec 31, 2021 at 13:14
  • $\begingroup$ @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. $\endgroup$
    – Ash
    Commented Jan 21, 2022 at 0:40
-1
$\begingroup$
Y = fft2(x);
imagesc(10*log10(abs(fftshift(Y))));
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.