Code for a picture to apply filters in frequency domain to it.

3 views (last 30 days)
Amy Peterson
Amy Peterson on 17 Oct 2021
Answered: Prachi Kulkarni on 20 Oct 2021
Apply the following filters to any image you prefer in the frequency domain. a. Average filter b. Gaussian filter c. Sharpening filter d. Sobel filter
  • To do that: Find the FFT transform of the image,
  • Find the FFT transform of the filter (you need to extend the size of the transformed filter so that it’s becomes same as transformed image size)
  • Pointwise Multiply the transformed image and transformed filter.
  • Find the inverse FFT transformation of the filtered image.
  • For every filter give the following: o Original image and its FFT transform o Filter and its FFT transform o Filtered image in frequency domain o Filtered image in spatial domain.
I have tried to figure out this code multiple times, and nothing seems to be working. If someone could help me on this, that would be amazing and I would be forever greatful!

Answers (1)

Prachi Kulkarni
Prachi Kulkarni on 20 Oct 2021
Please refer to the following example for a sample code.
I = imread("cameraman.tif"); % image of size 256x256
I = im2double(I);
F = fspecial("average",3); % average filter of size 3x3
Ipad = padarray(I,[3-1 3-1],0,"post"); % zero padding
Fpad = padarray(F,[256-1 256-1],0,"post"); % zero padding
Ifft = fft2(Ipad);
Ffft = fft2(Fpad);
Offt = Ifft.*Ffft;
Opad = ifft2(Offt);
O = Opad(2:end-1,2:end-1); % remove padding

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by