根据这个 Quora 答案,Gabor 滤波器是频域滤波器。而且,这里是一个Gabor 滤波器的实现,它imfilter()
用于实现过滤,这意味着
imfilter()
工作在频域。
现在,让我们看一下Source Code #1。
如果我更换
I_ffted_shifted_filtered = I_ffted_shifted.*Kernel;
和
I_filtered = imfilter(I, Kernel);
如下
function [out1, out2] = butterworth_lpf_imfilter(I, Dl, n)
Kernel = butter_lp_kernel(I, Dl, n);
I_filtered = imfilter(I, Kernel);
out1 = ifftshow(ifft2(I_filtered));
out2 = ifft2(ifftshift(I_filtered));
end
我们没有得到预期的输出,
为什么这不起作用?我的代码有什么问题?
源代码 #1
主文件
clear_all();
I = gray_imread('cameraman.png');
Dl = 10;
n = 1;
[J, K] = butterworth_lpf(I, Dl, n);
imshowpair(I, J, 'montage');
Butterworth_lpf.m
function [out1, out2] = butterworth_lpf(I, Dl, n)
Kernel = butter_lp_kernel(I, Dl, n);
I_ffted_shifted = fftshift(fft2(I));
I_ffted_shifted_filtered = I_ffted_shifted.*Kernel;
out1 = ifftshow(ifft2(I_ffted_shifted_filtered));
out2 = ifft2(ifftshift(I_ffted_shifted_filtered));
end
butter_lp_kernel.m
function k = butter_lp_kernel(I, Dl, n)
Height = size(I,1);
Width = size(I,2);
[u, v] = meshgrid( ...
-floor(Width/2) :floor(Width-1)/2, ...
-floor(Height/2): floor(Height-1)/2 ...
);
k = butter_lp_f(u, v, Dl, n);
function f = butter_lp_f(u, v, Dl, n)
uv = u.^2+v.^2;
Duv = sqrt(uv);
frac = Duv./Dl;
denom = frac.^(2*n);
f = 1./(1.+denom);
输出