I am trying to understand the meaning of FFT outputs with respect to images. Take a look at the following example:

import numpy as np
import matplotlib.pyplot as plt
import cv2

# Define gaussian, sobel, and laplacian (edge) filters

gaussian = (1/9)*np.array([[1, 1, 1],
                           [1, 1, 1],
                           [1, 1, 1]])

sobel_x= np.array([[-1, 0, 1],
                   [-2, 0, 2],
                   [-1, 0, 1]])

sobel_y= np.array([[-1,-2,-1],
                   [0, 0, 0],
                   [1, 2, 1]])

# laplacian, edge filter
laplacian=np.array([[0, 1, 0],
                    [1,-4, 1],
                    [0, 1, 0]])

filters = [gaussian, sobel_x, sobel_y, laplacian]
filter_name = ['gaussian','sobel_x', \
                'sobel_y', 'laplacian']

# perform a fast fourier transform on each filter
# and create a scaled, frequency transform image
f_filters = [np.fft.fft2(x) for x in filters]
fshift = [np.fft.fftshift(y) for y in f_filters]
frequency_tx = [np.log(np.abs(z)+1) for z in fshift]

# display 4 filters
for i in range(len(filters)):
    plt.subplot(2,2,i+1),plt.imshow(frequency_tx[i],cmap = 'gray')
    plt.title(filter_name[i]), plt.xticks([]), plt.yticks([])


It applies FFT transformation to several different image filters. Zero-frequency component is brought to the center of the image and the magnitudes are presented below:

enter image description here

It's a bit hard to understand what frequency means as regards images. Take for instance, the Gaussian filter, which is a solid 3x3 image. Would it be correct to say that its frequencies are all zeros? And if we consider Sobel_X, how do we find frequencies in that case?

My second question is what do the horizontal and vertical axes of these 3x3 maps represent? Are 0, 1, 2 frequency values or do they designate a number of a frequency component (so there are 3 horizontal and 3 vertical frequencies and their indices are shown in the axes)?

The last thing I am failing to understand are the magnitude values calculated for these filters. If I am not mistaken, the magnitude indicates how much a particular frequency is present in an image. The FFT map for the Laplacian filter has a black pixel in the middle. Does it mean it has only high frequency components and no zero-frequency? Why higher frequency magnitudes have the highest values (see white corners)?

  • $\begingroup$ Sorry, there were some mistakes in my answer. I found this referance though. I think this clarifies the answer. $\endgroup$ – havakok Jan 14 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.