我从this link找到了一个很好的Gabor滤波器源代码。代码非常干净并且有很好的文档记录。Gabor滤波器如何工作?
我的问题就在这里,
for i = 1:u
...............
...............
...............
for j = 1:v
tetav = ((j-1)/v)*pi;
.....................
for x = 1:m
for y = 1:n
xprime = ........
yprime = ........
gFilter(x,y) = ........
end
end
gaborArray{i,j} = gFilter;
end
end
是什么意思tetav = ((j-1)/v)*pi;
?它是弧度还是度数?如果它是弧度,为什么它不是180分呢?
为什么内核计算从1
到m
或n
?为什么不从-(m/2)
到(m+1)/2
?
源代码
gaborFeatures.m
function gaborResult = gaborFeatures(img,gaborArray,d1,d2)
if (nargin ~= 4) % Check correct number of arguments
error('Please use the correct number of input arguments!')
end
if size(img,3) == 3 % Check if the input image is grayscale
warning('The input RGB image is converted to grayscale!')
img = rgb2gray(img);
end
img = double(img);
% Filter input image by each Gabor filter
[u,v] = size(gaborArray);
gaborResult = cell(u,v);
for i = 1:u
for 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 be four input arguments (Number of scales and orientations and the 2-D size of the filter)!')
end
% Create u*v gabor filters each being an m by n matrix
gaborArray = cell(u,v);
fmax = 0.25;
gama = sqrt(2);
eta = sqrt(2);
for i = 1:u
fu = fmax/((sqrt(2))^(i-1));
alpha = fu/gama;
beta = fu/eta;
for j = 1:v
tetav = ((j-1)/v)*pi;
gFilter = zeros(m,n);
for x = 1:m
for 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
只要为'v'选择一个值,看看'((j-1)/ v)'在'j'从1变为'v'时的确很容易。你尝试过吗? – gnovice
cos文档页面的标题是[“以弧度表示的参数的余弦”](https://www.mathworks.com/help/matlab/ref/cos.html),如果有帮助的话。 (我希望“sin”的文档能够说出同样的内容,但我会留给你来验证。) – beaker