Open In App

Convolution Theorem for Fourier Transform MATLAB

A Convolution Theorem states that convolution in the spatial domain is equal to the inverse Fourier transformation of the pointwise multiplication of both Fourier transformed signal and Fourier transformed padded filter (to the same size as that of the signal). In other words, the convolution theorem says that Convolution in the spatial domain can be carried out in the frequency domain using Fourier transformation.

Equation for Discrete Fourier Transformation (DFT):



Equation for Inverse DFT:



 

 

Steps:

Function Used:

Example:

% MATLAB code for Convolution in Spatial Domain:
% CONVOLUTION IN SPATIAL DOMAIN
function f=Convolution(img)
 
%convert into grayscale if not.
[x,y,z]=size(img);
if(z==3)
    img=rgb2gray(img);
end
 
% Define averaging filter
mask=ones(5,5).*1/25;
Original_input_image=double(img);
convolved_image=conv2(Original_input_image,mask,'same');
 
% Display images.
imtool(Original_input_image,[]);
imtool(convolved_image,[]);
 
% Close all image tabs after 10s.
pause(10);
imtool close all;
end
 
% Utility code
k=imread("cameraman.jpg");
Convolution(k);

                    

Output:

Code Explanation:

Example:

% MATLAB code for Convolution in Frequency Domain:
% CONVOLUTION THEOREM FOR FOURIER TRANSFORMATION
function f=Convolution_Theorem(img)
 
% Convert into grayscale if not.
[x,y,z]=size(img);
if(z==3)
    img=rgb2gray(img);
end
 
% Define averaging filter
mask=ones(5,5).*1/25;
FT_img=fft2(img);
FT_mask=fft2(mask,x,y);
 
Fourier_Transformed_image=abs(log(fftshift(FT_img)));
Fourier_Transformed_mask=abs(log(fftshift(FT_mask)));
imtool(Fourier_Transformed_image,[]);
imtool(Fourier_Transformed_mask,[]);
 
pointwise_mul=FT_img.*FT_mask;
convolved_image=ifft2(pointwise_mul);
imtool(convolved_image,[]);
 
% Close all image tabs after 15s.
pause(15);
imtool close all;
end
 
% UTILITY CODE
k=imread("cameraman.jpg");
Convolution_Theorem(k);

                    

Output:

Code Explanation:

Fourier transformation is faster than convolution in the spatial domain. Computation complexity is less in the frequency domain. In MATLAB the inbuilt function “conv2” also uses the same technique to perform convolution. The image and the mask are converted into the frequency domain, by using Fourier Transformation. The inverse FT is performed on the pointwise multiplication of image and mask. 

If we perform the convolution as per the mathematics in the spatial domain, it would take more time as it includes more computation. If the filter size is small and the matrix is large then computational cost increase significantly. 


Article Tags :