如何在MATLAB中显示40 gabor滤波器 [英] How to show 40 gabor filter in matlab
问题描述
pre $ g $ g $ gbout gaborfilter1(B,sx,sy,f,theta(j)) ;
G {m,n,i,j} = Gf;
这是gabor过滤器类:
<$函数[gf,gabout] = gaborfilter(I,Sx,Sy,f,theta); p $ p>
如果isa(I,'double')〜= 1
I = double(I);
end
for x = -fix(Sx):fix(Sx)
for y = -fix(Sy):fix(Sy)
xPrime = x * cos(θ)+ y * sin(θ);
yPrime = y * cos(theta) - x * sin(theta); $($)$ b $ 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;
如果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)));
如果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 =零(S,D,winLen,winLen);
for d = 1:D
theta =(d-1)* pi / D;
for s = 1:S
scale = a ^( - (s-1));
gab = zeros(winLen); (x-x0)* cos(θ)+(y-y0)* sin(θ) );
Y =比例*( - (x-x0)* sin(θ)+(y-y0)*cosθ) (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
can someone help me how to show gabor filter in matlab, i can show it but its not what i want. this is my code :
[Gf,gabout] = gaborfilter1(B,sx,sy,f,theta(j));
G{m,n,i,j} = Gf;
and this is gabor filter class:
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);
Then, I imshow with this code:
imshow(G{m,n,i,j},[]);
and the results :
But i want this result, can someone help me how to slove this?
Use the following function. I hope this is useful.
----------------------------------------------------------------
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中显示40 gabor滤波器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!