Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中显示40 gabor滤波器_Matlab_Image Processing_Filter - Fatal编程技术网

如何在matlab中显示40 gabor滤波器

如何在matlab中显示40 gabor滤波器,matlab,image-processing,filter,Matlab,Image Processing,Filter,有人能帮我如何在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)

有人能帮我如何在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},[]);
结果是:

但是我想要这个结果,有人能帮我解决这个问题吗


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

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

----------------------------------------------------------------

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

将“cos”组件替换为复数部分->
复数(0,(2*pi*f*xprime))
ans还将方程乘以
(1/sqrt(2*Sy*Sx))的比例因子。

我想你需要发布更多的代码来帮助我们。例如,显示的是
gaborfilter
函数,而不是
gaborfilter1
函数。它们是一样的吗?我假设您正在循环中运行
gaborfilter1
,您可以发布该代码吗?我还怀疑你的Gabor滤波器公式是错误的。西格玛在哪里?你打算做什么?