KiMaN
KiMaN

Reputation: 319

Gaussian filter in fourier domain

I try to apply an Gaussian filter in Fourier domain with matlab, the result is blurred but the output image is messy like a puzzle, I don't know why!

img='src.pgm';
scale=10;

I=imread(img);
S=size(I);
TF_I=zeros([S(1) S(2)]);

TF_I= fft2(I);

mask = fspecial('gaussian',S(1),scale);

TF_mask=fft2(mask);

TF_out = TF_I.*TF_mask;

img_out=ifft2(TF_out);

img_out=uint8(img_out);

imshow(img_out);

Upvotes: 0

Views: 707

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60494

Try this:

TF_mask=fft2(ifftshift(mask));

The DFT (what fft computes) assumes the origin is at the top-left pixel. mask has the origin in the middle of the image. ifftshift shifts the origin to the top-left pixel.

Upvotes: 2

Related Questions