forked from olakiril/Libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gabor_fn.m
37 lines (31 loc) · 783 Bytes
/
gabor_fn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function gb=gabor_fn(bw,gamma,psi,lambda,theta)
% bw = bandwidth, (1)
% gamma = aspect ratio, (0.5)
% psi = phase shift, (0)
% lambda= wave length, (>=2)
% theta = angle in rad, [0 pi)
if nargin<1
bw = 2;
gamma = 0.5;
psi = 0;
lambda = 1;
theta = pi;
end
sigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1);
sigma_x = sigma;
sigma_y = sigma/gamma;
sz=fix(8*max(sigma_y,sigma_x));
if mod(sz,2)==0, sz=sz+1;end
% alternatively, use a fixed size
% sz = 60;
[x, y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2));
% x (right +)
% y (up +)
% Rotation
x_theta=x*cos(theta)+y*sin(theta);
y_theta=-x*sin(theta)+y*cos(theta);
gb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);
if ~nargout
imagesc(gb);
colormap gray
end