# Forward and Inverse Fourier Transform of an Image in MATLAB

In this article, we shall apply Fourier Transform on images. Fourier Transform is a mathematical technique that helps to transform Time Domain function x(t) to Frequency Domain function X(ω). In this article, we will see how to find Fourier Transform in MATLAB.

**Properties of Fourier Transform:**

**Linearity:****Scaling:**Scaling is the method that is used to change the range of the independent variables or features of data. If we stretch a function by the factor in the time domain then squeeze the Fourier transform by the same factor in the frequency domain.**Differentiation:**Differentiating function with respect to time yields to the constant multiple of the initial function.**Convolution:****Frequency Shift and Time Shift:**Frequency is shifted according to the coordinates. There is a duality between the time and frequency domains and frequency shift affects the time shift. The time variable shift also affects the frequency function. The time-shifting property concludes that a linear displacement in time corresponds to a linear phase factor in the frequency domain.

The image chosen for the experiment in this article is a famous cameraman image.

**Equation for DFT: **

**Equation for IDFT: **

**Steps:**

- Read the image.
- Apply forward Fourier transformation.
- Display log and shift FT images.

**Function Used:**

- imread( ) inbuilt function is used to image.
- fft2( ) inbuilt function is used to apply forward fourier transform on 2D signal.
- ifft2( ) inbuilt function is used to apply inverse Fourier transform on 2D signal.
- fftshift( ) inbuilt function is used to shift corners to center in FT image.
- log( ) inbuilt function is used to evaluate logarithm of FT complex signal.
- imtool( ) inbuilt function is used to display the image.

**Example:**

## Matlab

`% MATLAB code for Forward and ` `% Inverse Fourier Transform` ` ` `% FORWARD FOURIER TRANSFORM` `k=imread(` `"cameraman.jpg"` `);` ` ` `% Apply fourier transformation.` `f=fft2(k);` ` ` `% Take magnitude of FT.` `f1=abs(f);` ` ` `% Take log of magnitude of FT.` `f2=log(abs(f));` ` ` `% Shift FT from corners to central part.` `f3=log(abs(fftshift(f)));` ` ` `% Display all three FT images.` `imtool(f1,[]); ` `imtool(f2,[]);` `imtool(f3,[]);` ` ` `% Remove some frequency from FT.` `f(1:20, 20:40)=0;` `imtool(log(abs(f)),[]);` |

**Output:**

**Code Explanation:**

- k=imread(“cameraman.jpg”); This line reads the image.
- f=fft2(k); This line computes fourier transformation.
- f1=abs(f); This takes magnitude of FT.
- f2=log(abs(f)); This line takes log of magnitude of FT.
- f3=log(abs(fftshift(f))); This line shifts FT from corners to central part.
- f(1:20, 20:40)=0; This line remove frequencies from FT.

**Example:**

## Matlab

`% MATLAB code for INVERSE FOURIER TRANSFORM` `% apply inverse FT on FTransformed image.` `% we get original image in this step.` `j=ifft2(f);` ` ` `% Take log of original image.` `j1=log(abs(j));` ` ` `% Shift corners to center.` `j2=fftshift(j);` ` ` `% Again shift to get original image.` `j3=fftshift(j2);` ` ` `% Remove some frequency from FT image.` `f(1:20, 20:40)=0;` ` ` `% Apply inverse FT.` `j4=ifft2(f);` ` ` `% Display all 4 images.` `imtool(j,[]);` `imtool(j1,[]); ` `imtool(j2,[]);` `imtool(j3,[]);` `%j and j3 are same.` `imtool(abs(j4),[]);` |

**Output:**

**Code Explanation: **

- j=ifft2(f); This line computes inverse FT of FT image.
- f(1:20, 20:40)=0; This line removes some frequency from FT image.
- j4=ifft2(f); This line computes inverse FT after removing some frequencies.
- imtool(abs(j4),[]); This line displays modified image which contains some ringing artefacts.

**Properties:**

- There is no one-to-one correspondence between the cameraman image and the Fourier transform image.
- The cameraman image represents the intensities in the spatial domain.
- Fourier transformed image represents frequency in the frequency domain.
- Lower frequency represents the smooth part of the image while higher frequency represents the shape components like edges of an image.
- If the low-frequency part is removed from the frequency domain image then the spatial domain image will get blurred.
- If the anyone frequency value is removed (made 0) in the frequency domain image, that particular frequency will be removed (subtracted) from every intensity value in the spatial domain image.