2 D FFT and Image Filtering


In this post I will discuss the 2 D FFT in term of image processing.

Steps we are going to perform:

  1. Read input images and observe FFT of images.
  2. Generate noisy image with random noise.
  3. Analyze the FFT of Lena clean image and Lena noisy image.
  4. Use Gaussian filters in frequency domain to clean image
  5. Analysis of results.



Figure.1 shows the FFT of single color image and white and gray image FFT.

  • In single color image all pixel are same their is no variations in pixel color.
  • Frequency of image is almost zeros so we can see small dot at center.
  • That’s mean all frequency is concentrated near to zero.
  • In gray and white image color is changed in vertical direction (Y direction), FFT of image shows the frequency distributions in Y direction. No frequency changed in X direction.
  • If image is blur (means color variation in image is less) its FFT distribution will be concentrated. That’s help to find out amount of blur in image.


Figure.2 FFT on random noise
  • Random noise image have random pixel variation, that shows many random frequencies are present in noise image.
  • FFT of random noise image will be distributed in all direction without having any prominent frequency as shown in figure.2.


  • Figure.3 shows FFT of standard lena image we can see lot of information lie on center and some high prominent frequency content also present in image that makes image sharp.
  • In lena noisy image random noise is distributed in image but some information is their at center we can see some brightness at center .


  • If we take the filter which take out center frequency of image we can able to rid of random noise.
  • Let take the gaussian mask ( as shown in figure4)  and multiply it with image in frequency domain. (frequency domain multiplication is convolutions in special domain).
  • Inverse the image to special domain which is filtered image (shown in figure. 4).


  • Figure 5 shows the result of image filtering with many sizes of Gaussian mask.
  • Gaussian filter sigma is 5, image is too blurred and noise is removed.
  • When Gaussian sigma is 57, image is not cleaned.

So with the help of FFT we can find out the size and distribution of Gaussian filter according to our applications.


Some applications of FFT in image processing

  •  Feature extractions.
  • Image Compression.
  • Filtering
  • Find the amount of blur in image.
  • Many time used to speed up the 2 d convolution, operation like erosion, dilation.


MATLAB code:

%%%%%%%%%%%%%%%%%%%%%%code start%%%%%%%%%%%%%

clc;        % clear  screen

clear all  % clear all variables

close all

img = imread(‘lena’,‘jpg’); % load the image

img_gray = rgb2gray(img);

img_gray = double(img_gray);   % convert image to double data type

[row,col,channel] = size(img);

noise = 255*rand(row,col);         % generate random noise

noisy_img = (img_gray + noise)/2 ;    % create noisy image

% calculate fft  of clean image.

fftimg = fft2(img_gray);

% use fftshift to shift the fft in center

fft_img = fftshift(fftimg);

% calculate fft  of noisy image.

fftnoisy_img = fft2(noisy_img);

fft_noisy_img = fftshift(fftnoisy_img);

% Genrate gassuian filter with size of image and sigma 27.

H = fspecial(‘gaussian’,[row, col] ,27);

% multiplication of gausaain filter with noisy image in frequency domain

fft_filter_img = H.*fft_noisy_img;

% take inverse of fftshift

fft_filterimg = ifftshift(fft_filter_img);

% calculate absolute value of inverse FFT that is filtered image.

filterimg = abs(ifft2(fft_filterimg));

%plot all the results

subplot(2,2,1), imshow(uint8(img_gray))

title(‘Lena image’)

subplot(2,2,2), pcolor((log(abs(fft_img)))); shading interp

colormap(gray), set(gca,‘Xtick’,[],‘Ytick’,[])

title(‘FFT of Lena image’)

subplot(2,2,3), imshow(uint8(noisy_img))

title(‘Lena noisy image’)

subplot(2,2,4), pcolor((log(abs(fft_noisy_img)))); shading interp

colormap(gray), set(gca,‘Xtick’,[],‘Ytick’,[])

title(‘FFT of Lena noisy image’)


subplot(2,2,1), imshow(uint8(noisy_img))

title(‘Lena noisy image’)

subplot(2,2,2), pcolor((log(abs(fft_noisy_img)))); shading interp

colormap(gray), set(gca,‘Xtick’,[],‘Ytick’,[])

title(‘FFT of Lena noisy image’)


title(‘gaussian filter mask’)


title(‘Filtered image’)



title(‘gaussian filter mask of sigma 27’)


title(‘Filtered image with gaussian’)


%%%%%%%%%%%%%%%%%%%%%code end%%%%%%%%%%%%%%%%





Happy Learning





















Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s