matlab - Can `imfilter` work in the frequency domain? -


according this quora answer, gabor filter frequency domain filter. and, here implementation of gabor filter uses imfilter() achieve filtering, means

imfilter() works in frequency domain.

now, let @ source code #1.

if replace

i_ffted_shifted_filtered = i_ffted_shifted.*kernel; 

with

i_filtered = imfilter(i, kernel); 

as 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 expected output,

enter image description here

why doesn't work? what problem in code?


source code #1

main.m

clear_all(); = 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

enter image description here

imfilter takes spatial domain representation of image , spatial domain kernel h, , returns spatial domain image, b. whatever domain or algorithm used compute b implementation detail. said, imfilter uses spatial convolution compute b.

as can see in comments above, gabor filter not "frequency domain filter". gabor filter lti , such filtering operation can implemented in either domain. should make sense, given "gaussian modulated sinusoid" waveforms shown in literature when discussing gabor filter banks in spatial domain.

example of spatial domain gabor filter kernels

it happens in spatial domain, gabor filter kernels can large , non-separable in general case unless theta multiple of 90 degrees unless want use approximate techniques. so, common use frequency domain implementation of gabor filtering speed purposes. imgaborfilt in ipt.

if have ipt, recommend looking @ code in gabor , imgaborfilt more information.

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

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

in implementation using, using frequency domain implementation. if want use imfilter, have pass in equivalent spatial domain representation of gabor filter. not make sense pass frequency domain representation of gabor filter imfilter doing. not gabor filtering operation.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -