.st0{fill:#FFFFFF;}

How to Convert Images from Spatial domain to Frequency domain? 

 February 4, 2022

By  Sneha

You may be familiar with image filtering applications in your phone which enhance the image.

Image Enhancement

Image Enhancement

Do you want to research celestial object images and study energy distribution?

Energy Distribution

Energy Distribution

These two can be successfully achieved by analyzing the image in the frequency domain.

Introduction: 

Image in spatial domain means analyzing image as it is, i.e., the value of the pixel of the image change concerning the scene. But the image in the frequency domain means analyzing the image concerning its frequency, i.e., the rate at which pixel values are changing in the spatial domain. So, neither image enhancement nor research on distributed energy is possible in the spatial domain. So converting an image from the spatial domain to the frequency domain is necessary.

Spatial domain

Spatial domain

Frequency domain

Frequency domain

Steps to convert image from spatial domain to frequency domain:

  • Read the image which needs to be converted, analyzed or enhanced.                      

imread('image 3.jpg');

Image for Processing

Image for Processing

  • Convert image from RGB to Gray image. Since digital/binary (Black & White) analysis is easy and quick. The image will be in the form of a matrix in MATLAB.

               rgb2gray(img);

GrayScale Image

GrayScale Image

  • Normalize the image to analyze the image in a better manner.

             double(mat2gray(img1));

  • Now convert image from spatial domain to frequency domain. It can be achieved using Fourier transform, i.e., take Fourier transform of the normalized image. Usually, the “centre” or the ‘0’ frequency location of the spectrum is at the first and last element, and the “ends” of the spectrum (highest frequency) are at the center of the array. That’s just how the FFT works. But that’s confusing for display because the low frequencies appear in two disconnected locations. So fftshift() moves the zero frequency location to the middle of the array so that when you display it with imshow() or plot(), it looks like you would expect

fftshift(fft2(img2));

Fourier transformed image

Fourier transformed image

  • Then take the logarithm of the Fourier transformed image. It increases the magnitude of the image and keeps only the real part of the image. Since image processing of complex numbers doesn’t work well.

log(1+abs(imgF));

Real Part of fourier transformed image

Real Part of fourier transformed image

  • Display the image. Take a bar graph of the image matrix to analyze the energy distribution of the image.

                     bar(I);

Frequency of Image

Frequency of Image

MATLAB CODE:

%Conversion of image from Spatial domain to frequency domain
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Read the image that you want in frequency domain
clc;
clear;
close all;
img=imread('image 3.jpg');
% Convert RGB image to gray image
img1=rgb2gray(img);
% normalize the matrix to double
img2=double(mat2gray(img1));
% Take Fourier transform of the image then center shift the Fourier
% transformed imageimg
F=fftshift(fft2(img2));
% Take log of the image matrix
I=log(1+abs(imgF));
% Plot the images
subplot(2,2,1);
imshow(img);
title('Original Image');
subplot(2,2,2);
imshow(I);
title('Fourier transform of image');
subplot(2,2,3);
bar(I);
title('Frequency bar graph of image');
imginv=abs(ifft2(imgF));
subplot(2,2,4);
imshow(imginv);
title('Inverse fourier transform of image')

Conclusion:

Not only Image Enhancement and study on energy distribution but several applications of Fourier transform in Image processing such as converted image frequencies are used to produce sound/audio, identify the type of Electromagnetic Wave they (Image) contain, etc. Let just recall the steps:

  1. Read Image
  2. Convert RGB to Grayscale image
  3. Normalize the image.
  4. Take Fourier transform.

Did you find some helpful content from our video or article and now looking for its code, model, or application? You can purchase the specific Title, if available, and instantly get the download link.

Thank you for reading this blog. Do share this blog if you found it helpful. If you have any queries, post them in the comments or contact us by emailing your questions to [email protected]. Follow us on LinkedIn Facebook, and Subscribe to our YouTube Channel. If you find any bug or error on this or any other page on our website, please inform us & we will correct it.

If you are looking for free help, you can post your comment below & wait for any community member to respond, which is not guaranteed. You can book Expert Help, a paid service, and get assistance in your requirement. If your timeline allows, we recommend you book the Research Assistance plan. If you want to get trained in MATLAB or Simulink, you may join one of our training modules. 

If you are ready for the paid service, share your requirement with necessary attachments & inform us about any Service preference along with the timeline. Once evaluated, we will revert to you with more details and the next suggested step.

Education is our future. MATLAB is our feature. Happy MATLABing!

About the author 

Sneha

I am Sneha G.K . I am an Electronic and Communication Engineering Student. I am a passionate Programmer and a researcher too. I enjoy exploring new things everyday and experimenting it.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Connect with MATLAB Helper ®

Follow: YouTube Channel, LinkedIn Company, Facebook Page, Instagram Page

Join Community of MATLAB Enthusiasts: Facebook Group, Telegram, LinkedIn Group

Use Website Chat or WhatsApp at +91-8104622179

>