2
votes

I just stumbled upon this question and am trying to know about its effects by practically testing it.

Consider a (nxn) Gaussian kernel. Choose the appropriate variance for the same. Perform linear and circular convolution in the frequency domain with this kernel on an image. Can you say anything about the results?

I tried to implement the above in Matlab , with the following code.

     clc;
     close all;
     clear all;

     I = imread('my_face.jpg');
     Irez = imresize(I,[512 512]); %resize image
     figure(1);
     imshow(Irez);
     Irez = rgb2gray(Irez);

     M = 2*size(I,1)+1;
     N = 2*size(I,2)+1;

     Ifreq = fft2(I,M,N);
     gaus = fspecial('gaussian',5,0.7);

     Igaus = conv2(gaus,abs(Ifreq));
     Iface = real(ifft2(Igaus));
     Iout = Iface(1:size(I,1),1:size(I,2));
     figure(2)
     imshow(Iout);

My questions are :

  1. Am I on the right track? Am I doing what the problem is expecting me to? Or should I take or consider the fft of the gaussian kernel or have a similar Gaussian kernel in frequency domain? Please do tell me if you guys found the right way to achieve this.

  2. Linear convolution's equivalent is multiplication. What is the equivalent of circular convolution?

Moreover, the above code is giving me the following error :

Undefined function or method 'conv2' for input arguments of type 'double' and attributes 'full 3d real'

It is obvious that both have to be double for input of conv2. Can you please help me to practically implement the problem?

1
You're getting confused. It appears you're taking the DFT of an image, applying a convolution to it in the "frequency domain" and then taking the inverse DFT. The point of the question is to show that convolution in the "spatial domain" can be done in the "frequency domain," but the operation is different. To do a circular convolution in the "frequency domain," you need to take the DFT of the image and kernel, multiply their fourier coefficients elementwise, and then take the inverse DFT of the result. This is a (sometimes) faster way to do filtering.Justin
At least this would be my interpretation of the question... but it does seem a little unclear...Justin
@jucestain you are right. I have to consider the dft of both the gaussian and the image and try the convolution in frequency domain. can you please tell me in detail as to how I can go about this? Really sorry for asking again.Lakshmi Narayanan

1 Answers

2
votes

I seems that you are providing right arguments in fspecial function. You have to specify the number of columns and rows in this function. I copied the below lines from matlab help:

h = fspecial('average', hsize) returns an averaging filter h of size hsize. The argument hsize can be a vector specifying the number of rows and columns in h, or it can be a scalar, in which case h is a square matrix. The default value for hsize is [3 3].

gaus = fspecial('gaussian', [M N],5,0.7);

You can find more about it here: http://www.mathworks.se/help/images/ref/fspecial.html