Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top