我刚刚偶然发现了这个问题,并试图通过实际测试来了解其效果。
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?
我尝试使用以下代码在 Matlab 中实现上述内容。
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);
我的问题是:
我走的路正确吗?我正在做问题所期望的事情吗?或者我应该采用或考虑高斯核的 fft 或在频域中具有类似的高斯核?请告诉我你们是否找到了实现这一目标的正确方法。
线性卷积的等价物是乘法。循环卷积相当于什么?
此外,上面的代码给了我以下错误:
Undefined function or method 'conv2' for input arguments of type 'double' and attributes 'full 3d real'
很明显,对于 conv2 的输入来说,两者都必须是 double。你能帮我实际解决这个问题吗?
最佳答案
我似乎您在 fspecial 函数中提供了正确的参数。您必须在此函数中指定列数和行数。我从 matlab 帮助中复制了以下几行:
h = fspecial('average', hsize) 返回大小为 hsize 的平均滤波器 h。参数 hsize 可以是指定 h 中的行数和列数的向量,也可以是标量,在这种情况下 h 是方阵。 hsize 的默认值为 [3 3]。
gaus = fspecial('gaussian', [M N],5,0.7);
您可以在这里找到更多相关信息:http://www.mathworks.se/help/images/ref/fspecial.html
关于matlab - 频域卷积matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18874530/