gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:50:08 26 4
gpt4 key购买 nike

有人可以帮我如何在 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},[]);

和结果:

enter image description here

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

gabor filter

最佳答案

使用以下函数。我希望这有用。
-------------------------------------------------- --------------

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

Sample Image
-------------------------------------------------- --------------

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

关于matlab - 如何在matlab中显示40个gabor滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com