Forward and Inverse Fourier Transform of an Image in MATLAB


In mathematics, the Fourier transform is a mathematical tool used for converting a function or signal from the time domain to the frequency domain. It is widely used in the field of signal processing, communication, image processing and analysis, etc.

Before proceed to find the forward and inverse Fourier transformer of an image using MATLAB, let us get a brief overview of Fourier transform and its inverse.

Forward Fourier Transform

Fourier transform or Forward Fourier transform is a mathematical operation that is used to transform a signal from the time domain into the frequency domain.

Therefore, the forward Fourier transform expresses a signal in terms of its frequency components. When we perform forward Fourier transform of a signal, then it produces a complex valued function which represents the amplitude and phase of the input signal at different frequencies.

Mathematically, the Fourier transform of a signal "x(t)" in time domain is defined as,

$$\mathrm{X(\omega)=\int_{−\infty}^{\infty}x(t)e^{−j\omega t}dt}$$

Where, X(ω) is the Fourier transform of x(t).

Now, let us discuss about the inverse Fourier transform.

Inverse Fourier Transform

The inverse Fourier transform is the reverse operation of the forward Fourier transform. It is defined as a mathematical operation which converts a frequency domain signal into the time domain signal.

In signal processing, it is mainly used to reconstruct the original signal from the transformed signal.

Mathematically, the inverse Fourier transform of a frequency domain signal can be defined as,

$$\mathrm{x(t)=\frac{1}{2\pi} \int_{−\infty}^{\infty}X(\omega)e^{j\omega t}\:d\omega}$$

Here, x(t) is the reconstructed signal from its Fourier transformed version.

This is all about Forward Fourier Transform and Inverse Forward Fourier Transform. Let us now discuss how to find the forward and inverse Fourier transforms of an image using MATLAB.

Forward Fourier Transform of Image using MATLAB

In MATLAB, we can use the 'fft2' function to perform the forward Fourier transformation of an image. The step-by-step procedure to find the forward Fourier transform of an image using MATLAB is explained below:

Step (1) – Read the original input image and convert it into grayscale if required.

Step (2) – Perform Fourier transformation of the image using the 'fft2' function.

Step (3) – Shift the Fourier transform from corners to the center by using the 'fftshift' function.

Step (4) – Take the absolute value of the shifted Fourier transform to calculate its magnitude spectrum.

Step (5) – Display the magnitude spectrum of the Fourier transform.

Example

Now, let us consider an example program in MATLAB for better understanding of the concept.

% MATLAB code to find forward Fourier transform of an image
% Read the original input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425236.jpg');

% Convert the input image to grayscale
gray_img = rgb2gray(img);

% Calculate Fourier Transform of the image
FT = fftshift(fft2(gray_img));

% Calculate the magnitude spectrum of Fourier transform
mag_spect = abs(FT);

% Take the log of magnitude spectrum 
mag_spect_log = log(1 + mag_spect);	% Adding 1 to avoid log(0)

% Display the magnitude spectrum of the Fourier transform
figure;
subplot(1, 2, 1);
imshow(mag_spect, []);
title('Magnitude Spectrum of FT');

subplot(1, 2, 2);
imshow(mag_spect_log, []);
title('Log Magnitude Spectrum of FT');
colormap(gca, 'jet');
colorbar;

Output

This is how we can find the forward Fourier transform of an image in MATLAB. Now, let us learn how to find the inverse Fourier transform of an image.

Inverse Fourier Transform of Image using MATLAB

MATLAB provides a built-in function 'ifft2' to find inverse Fourier transform of a function or a signal.

Here, we have explained the step-by-step process to find the inverse Fourier transform of an image using MATLAB:

Step (1) – Read the Fourier transformed image.

Step (2) – Apply the 'ifft2' function to find the inverse Fourier transformed image.

Step (3) – Take the log of the absolute value of the inverse Fourier transformed image.

Step (4) – Display the inverse Fourier transformed image.

Example

The following example program demonstrates the practical implementation of these steps to find the inverse Fourier transform of an image using MATLAB.

% MATLAB code to perform Inverse Fourier Transform of an image
% Read the original input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425236.jpg');

% Convert the input image to grayscale
gray_img = rgb2gray(img);

% Calculate Fourier Transform of the image
FT = fftshift(fft2(gray_img));

% Find inverse Fourier Transform of the Fourier transformed image 
inverse_FT_img = ifft2(ifftshift(FT));	% FT is the Fourier transformed image

% Take the log of the absolute value of the inverse transformed image
inverse_FT_img_log = log(abs(inverse_FT_img));

% Display the original, log-transformed, and inverse transformed images
subplot(2, 2, 1);
imshow(gray_img);
title('Original Image');

subplot(2, 2, 2);
imshow(inverse_FT_img_log, []);
title('Log Inverse Transformed Image');

subplot(2, 2, 3);
imshow(abs(inverse_FT_img), []);
title('Inverse Transformed Image');

Output

This how we can find the inverse Fourier transform of an image in MATLAB by following simple steps.

Conclusion

In this tutorial, we explained the concept of Fourier transform (FT) and inverse Fourier transform (IFT). We have also explained how to find the forward Fourier transform and inverse Fourier transform in MATLAB with the help of example programs. You can try the above codes with your own images to find their FT and IFT.

Updated on: 07-Sep-2023

216 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements