VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-find-the-fourier-transform-of-an-image-using-opencv-python/

⇱ How to find the Fourier Transform of an image using OpenCV Python? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to find the Fourier Transform of an image using OpenCV Python?

Last Updated : 8 Jun, 2026

Fourier Transform is a mathematical technique used to analyze the frequency components of an image. It converts an image from the spatial domain to the frequency domain, making it useful for image filtering, compression, enhancement, and feature extraction.

  • Low-frequency components represent smooth regions and overall image structure.
  • High-frequency components represent edges, textures, and fine details.

The continuous Fourier Transform is given by:

Steps to find the Fourier Transform of an image

In this program, we will find the Discrete Fourier Transform (DFT) of an input image using OpenCV. The frequency components are processed and the resulting magnitude spectrum is displayed to visualize the image in the frequency domain.

Input Image:

👁 Dhoni-dive_165121_730x419-m

Step 1: Import the Required Libraries

Importing NumPy for numerical operations, OpenCV for image processing, and Matplotlib for visualization.

Step 2: Load the Image

Loading the input image in grayscale mode using the cv2.imread() function, as Fourier Transform is typically applied to grayscale images.

Step 3: Compute the Discrete Fourier Transform

Converting the image from the spatial domain to the frequency domain using the cv2.dft() function.

Step 4: Shift the Zero-Frequency Component to the Center

A square mask is created around the center of the spectrum to preserve low-frequency components while suppressing high-frequency components.

Step 5: Apply the Mask and Perform Inverse Shift

The mask is applied to the shifted spectrum. The modified spectrum is then shifted back before performing the inverse transform.

Step 6: Compute the Inverse DFT and Magnitude Spectrum

The inverse DFT reconstructs the image from the filtered frequency spectrum. The magnitude is calculated to visualize the intensity of the reconstructed image.

Step 7: Display the Results

Finally, displaying the original image and the resulting magnitude spectrum using Matplotlib.

Output:

👁 Discrete Fourier transform - Geeksforgeeks
Discrete Fourier transform
Comment