`imfilter` 可以在频域工作吗?

Can `imfilter` work in the frequency domain?

根据this Quora answer, Gabor filter is a frequency domain filter. And, here is an implementation的Gabor filter是用imfilter()来实现过滤的,也就是说

imfilter() works in the frequency domain.

现在,让我们看一下源代码#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

main.m

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);

输出

imfilter 采用图像 A 和空间域内核 h 的空间域表示,以及 returns 空间域图像 B。用于计算 B 的任何域或算法都是实现细节。也就是说,imfilter 使用空间卷积来计算 B。

如您在上面的评论中所见,Gabor 滤波器不是 "frequency domain filter"。 Gabor 过滤器是 LTI,因此过滤操作可以在任一域中实现。这应该是有道理的,因为在讨论 Gabor 滤波器组时文献中经常显示的 "gaussian modulated with a sinusoid" 波形是在空间域中。

碰巧在空间域中,Gabor 滤波器内核会变大并且在一般情况下是不可分离的,除非 theta 是 90 度的倍数,除非您想使用近似技术。因此,出于速度目的,通常使用 Gabor 滤波的频域实现。这就是 imgaborfilt 在 IPT 中所做的。

如果您有 IPT,我建议您查看 gabor 和 imgaborfilt 中的代码以获取更多信息。

https://www.mathworks.com/help/images/ref/imgaborfilt.html

https://www.mathworks.com/help/images/ref/gabor.html

在您使用的实现中,他们使用的是频域实现。如果要使用 imfilter,则必须传入 Gabor 滤波器的等效空间域表示。像您当前所做的那样将 Gabor 滤波器的频域表示形式传递给 imfilter 是没有意义的。那不是Gabor过滤操作。