TLD
TLD

Reputation: 8135

Working with Gaussian filter in frequency domain + Matlab

I read about Gaussian filter in frequency domain, but there is some points I can't understand here:

  1. Will the Gaussian filter is always a square matrix?

  2. If 1's answer is yes, what will happen if my image is a rectangle matrix? In Matlab, I read the image, then use fft2 to convert it from spatial domain to frequency domain, then I used ffshift to centralize it. What I want is multiply the frequency domain matrix of image to the Gaussian filter matrix, then converting the result to spatial domain by using ifft2, but because of different size of Gaussian filter matrix and frequency domain matrix of image, they can't be multiplied together. (I'm not using conv2 and fspectial here).

Upvotes: 4

Views: 8391

Answers (1)

Shai
Shai

Reputation: 114926

A Guassian filter is in fact circular since it is a function of the distance from its center. A rectangle matrix is used because it is more convenient.
What you can do in order to overcome the size differences is to zero-pad the filter:

img = imread( imgFileName ); % read image, use gray-level images here.
IMG = fft2( img ); % Fourier of img
sz = size( img );
h = fspecial( 'gaussian', sz, sigma ); % create a filter with std sigma same size as img
H = fft2( h ); % Fourier of filter
F = IMG.*H; % filter in Fourier space
f = ifft2( F ); % back to spatial domain. 

Upvotes: 1

Related Questions