0001 function [G, symbol] = GaborFilter(scale, orient)
0002
0003
0004
0005
0006 expand = 12; h = floor(scale * expand+.5);
0007 alpha = (pi * orient)/180;
0008 Gauss = zeros(h+h+1);
0009 Gcos = zeros(h+h+1); Gsin = zeros(h+h+1);
0010 symbol = zeros(h+h+1);
0011 for x0 = -h : h
0012 for y0 = -h : h
0013 if (x0^2+y0^2>h^2)
0014 inCircle = 0;
0015 else
0016 inCircle = 1;
0017 end
0018 x = (x0 * cos(alpha) + y0 * sin(alpha))/scale;
0019 y = (y0 * cos(alpha) - x0 * sin(alpha))/scale;
0020 g = exp(-(4*x^2+y^2)/100)/50/pi/scale^2;
0021 Gauss(h+x0+1,h+y0+1) = g*inCircle;
0022 Gcos(h+x0+1, h+y0+1) = g*cos(x)*inCircle;
0023 Gsin(h+x0+1, h+y0+1) = g*sin(x)*inCircle;
0024 symbol(h+x0+1, h+y0+1) = (abs(x)<3.4)*inCircle;
0025 end
0026 end
0027 s = sum(Gauss(:)); sc = sum(Gcos(:)); r = sc/s;
0028 Gcos = Gcos - Gauss*r;
0029 Scos = sqrt(sum(sum(Gcos.^2))); Ssin = sqrt(sum(sum(Gsin.^2)));
0030 Gcos = Gcos/Scos; Gsin = Gsin/Ssin;
0031 G = Gcos + sqrt(-1)*Gsin;
0032
0033
0034
0035
0036
0037
0038