matlab - How does the Gabor filter work? -
i have found gabor filter source code this link. code clean , well-documented.
my question here,
for = 1:u ............... ............... ............... j = 1:v tetav = ((j-1)/v)*pi; ..................... x = 1:m y = 1:n xprime = ........ yprime = ........ gfilter(x,y) = ........ end end gaborarray{i,j} = gfilter; end end
what mean tetav = ((j-1)/v)*pi;
? radian or degree? if radian, why wasn't divided 180?
why kernel computation go 1
m
or n
? why not -(m/2)
(m+1)/2
?
source code
gaborfeatures.m
function gaborresult = gaborfeatures(img,gaborarray,d1,d2) if (nargin ~= 4) % check correct number of arguments error('please use correct number of input arguments!') end if size(img,3) == 3 % check if input image grayscale warning('the input rgb image converted grayscale!') img = rgb2gray(img); end img = double(img); % filter input image each gabor filter [u,v] = size(gaborarray); gaborresult = cell(u,v); = 1:u j = 1:v gaborresult{i,j} = imfilter(img, gaborarray{i,j}); end end
gaborfilterbank.m
function gaborarray = gaborfilterbank(u,v,m,n) if (nargin ~= 4) % check correct number of arguments error('there must 4 input arguments (number of scales , orientations , 2-d size of filter)!') end % create u*v gabor filters each being m n matrix gaborarray = cell(u,v); fmax = 0.25; gama = sqrt(2); eta = sqrt(2); = 1:u fu = fmax/((sqrt(2))^(i-1)); alpha = fu/gama; beta = fu/eta; j = 1:v tetav = ((j-1)/v)*pi; gfilter = zeros(m,n); x = 1:m y = 1:n xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav); yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav); gfilter(x,y) = (fu^2/(pi*gama*eta))*exp(-((alpha^2)*(xprime^2)+(beta^2)*(yprime^2)))*exp(1i*2*pi*fu*xprime); end end gaborarray{i,j} = gfilter; end end
what mean tetav = ((j-1)/v)*pi;?
this means tetav
take on increasingly larger pieces of pi; starting 0 , increasing whole thing (i.e. 3.14159...). there 180 degrees or pi radians in half circle. tetav taking on increasingly portions of half circle.
is radian or degree?
it radians.
if radian, why wasn't divided 180?
radians desired unit here (for whoever programmed this). have instead multiplied pi if wanted in degrees. if, hypothetically, thinking expression ((j-1)/v)
in degrees , needed converted radians multiplication of pi/180, mean function cover, @ most, 1 degree of circle.
why kernel computation go 1 m or n? why not -(m/2) (m+1)/2?
it because chose instead handle -(m/2) (m+1)/2 inside loop. in code posted gaborfilterbank.m file:
xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav); yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav);
since sin , cosine being combined, you'll getting full circle covered gabor filter. , offset adjusted x , y center points -((m+1)/2) calls. example, when x = 1 expression (x-((m+1)/2)) becomes -(m+1)/2+1 or -m/2+0.5 , when x = m, same expression becomes m/2+0.5, still covering range wondering about.
Comments
Post a Comment