According to this Quora answer, Gabor filter is a frequency domain filter. And, here is an implementation of Gabor filter which uses imfilter()
to achieve the filtering, which means that
imfilter()
works in the frequency domain.
Now, let us look at Source Code #1.
If I replace
I_ffted_shifted_filtered = I_ffted_shifted.*Kernel;
with
I_filtered = imfilter(I, Kernel);
as the following
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
we don't obtain the expected output,
Why doesn't this work? What is the problem in my code?
Source Code #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);
Output