Search code examples
imagematlabimage-processingfftfrequency-domain

B&W Dots in Frequency domain figure of an image


I have this simple line of code that reads an image and takes a fourier transform of the image using fft2 function of matlab and then bringing the lower frequencies to the center of the figure by fftshift.
The problem is that in the figure of the image in frequency domain:

1) Which of the Black/White dots are representing High-frequencies?
2) Does Density of each Black/White dots shows the strength of each frequencies coefficient?

clc;
clear all;
format short;
format compact;
im=imread('cameraman.tif');
figure,imshow(im);
F=fftshift(fft2(im));
figure,imshow(uint8(abs(F)));

Solution

  • Well for one thing you aren't visualizing the magnitude of the spectrum properly. You are naively casting the result to uint8. Therefore, any values that are greater than 255 get truncated to 255. One thing people usually do is take the logarithm of the spectrum and adding 1 before taking the log to ensure no undefined errors.

    Therefore, do this:

    figure; imshow(log(1 + abs(F)), []);
    

    You get this picture instead:

    That's a much better representation of the spectrum. The DC coefficient has the highest intensity and that's in the middle of the image. The high frequency coefficients move towards the outer edges of the spectrum. You see that there are lines at various orientations. These actually given you the orientation of the most prominent edges in the image, starting with the vertical line, that tells you that there are a lot of vertical lines in the cameraman image, which makes sense.

    Also, you are correct in that the strength of the coefficient corresponds to the intensity of the point in the image. Each point in this image tells you the strength of the horizontal and vertical spatial frequency experienced at this point.