3

有人可以帮助我如何在 matlab 中显示 gabor 过滤器,我可以显示它,但它不是我想要的。这是我的代码:

 [Gf,gabout] = gaborfilter1(B,sx,sy,f,theta(j));


G{m,n,i,j} = Gf;

这是 gabor 过滤器类:

function [Gf,gabout] = gaborfilter(I,Sx,Sy,f,theta);

if isa(I,'double')~=1 
    I = double(I);
end

for x = -fix(Sx):fix(Sx)
    for y = -fix(Sy):fix(Sy)
        xPrime = x * cos(theta) + y * sin(theta);
        yPrime = y * cos(theta) - x * sin(theta);
        Gf(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*((xPrime/Sx)^2+(yPrime/Sy)^2))*cos(2*pi*f*xPrime);
    end
end

Imgabout = conv2(I,double(imag(Gf)),'same');
Regabout = conv2(I,double(real(Gf)),'same');

gabout = sqrt(Imgabout.*Imgabout + Regabout.*Regabout);

然后,我用这段代码显示:

imshow(G{m,n,i,j},[]);

结果:

在此处输入图像描述

但我想要这个结果,有人可以帮我解决这个问题吗?

加博过滤器

4

2 回答 2

1

使用以下功能。我希望这很有用。
-------------------------------------------------- --------------

gfs = GaborFilter(51,0.45,0.05,6,4);
n=0;
for s=1:6
   for d=1:4
        n=n+1;
        subplot(6,4,n)
        imshow(real(squeeze(gfs(s,d,:,:))),[])
   end
end

示例图片
------------------------------------------------ ----------------

function gfs = GaborFilter(winLen,uh,ul,S,D)

% gfs(SCALE, DIRECTION, :, :)

winLen = winLen + mod(winLen, 2) -1;
x0 = (winLen + 1)/2;
y0 = x0;

if S==1
    a = 1;
    su = uh/sqrt(log(4));
    sv = su;
else
    a = (uh/ul)^(1/(S-1));
    su = (a-1)*uh/((a+1)*sqrt(log(4)));
    if D==1
        tang = 1;
    else
        tang = tan(pi/(2*D));
    end
    sv = tang * (uh - log(4)*su^2/uh)/sqrt(log(4) - (log(4)*su/uh)^2);
end

sx = 1/(2*pi*su);
sy = 1/(2*pi*sv);
coef = 1/(2*pi*sx*sy);

gfs = zeros(S, D, winLen, winLen);

for d = 1:D
    theta = (d-1)*pi/D;
    for s = 1:S
        scale = a^(-(s-1));
        gab = zeros(winLen);
        for x = 1:winLen
            for y = 1:winLen
                X = scale * ((x-x0)*cos(theta) + (y-y0)*sin(theta));
                Y = scale * (-(x-x0)*sin(theta) + (y-y0)*cos(theta));
                gab(x, y) = -0.5 * ( (X/sx).^2 + (Y/sy).^2 ) + (2*pi*1j*uh)*X ;
            end
        end
        gfs(s, d, :, :) = scale * coef * exp(gab); 
    end
end
于 2013-11-24T22:34:26.917 回答
0

用复数部分替换“cos”分量-> complex(0, (2*pi*f*xprime))ans 也将方程乘以(1/sqrt(2*Sy*Sx)).

于 2016-03-19T17:14:53.023 回答