# gaborfilter

## PURPOSE

gaborfilter - generate Gabor filter at fixed scale and orientation

## SYNOPSIS

function [G, symbol] = gaborfilter(scale, orientation)

## DESCRIPTION

     gaborfilter - generate Gabor filter at fixed scale and orientation

     "G" is the Gabor pair
     "symbol" is the bar for display

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- makefilter makefilter - Make Gabor filters at fixed scale with norient orientations

## SOURCE CODE

    0001 function [G, symbol] = gaborfilter(scale, orientation)
    0002 % gaborfilter - generate Gabor filter at fixed scale and orientation
    0003 %
    0004 % "G" is the Gabor pair
    0005 % "symbol" is the bar for display
    0006
    0007 expand = 12; b = floor(scale * expand+.5);  % b is the half size or radius
    0008 theta = (pi * orientation)/180;  % theta is orientation
    0009 Gauss = zeros(b+b+1);  % Gaussian function
    0010 Gcos = zeros(b+b+1); Gsin = zeros(b+b+1); % Gabor cos and sine pair
    0011 symbol = zeros(b+b+1);
    0012 for x0 = -b : b
    0013     for y0 = -b : b
    0014         if (x0^2+y0^2>b^2)
    0015             fac = 0;  % zeros for pixels outside the circle
    0016         else
    0017             fac = 1;
    0018         end
    0019         x = (x0 * cos(theta) + y0 * sin(theta))/scale;
    0020         y = (y0 * cos(theta) - x0 * sin(theta))/scale;
    0021         g = exp(-(4*x^2+y^2)/100)/50/pi/scale^2;
    0022         Gauss(b+x0+1,b+y0+1) = g*fac;
    0023         Gcos(b+x0+1, b+y0+1) = g*cos(x)*fac;
    0024         Gsin(b+x0+1, b+y0+1) = g*sin(x)*fac;
    0025         symbol(b+x0+1, b+y0+1) = (abs(x)<b/2.5)*fac; % make a bar
    0026     end
    0027 end
    0028 s = sum(Gauss(:)); sc = sum(Gcos(:)); r = sc/s;
    0029 Gcos = Gcos - Gauss*r;   % mean is 0 by substracting DC component
    0030 Scos = sqrt(sum(sum(Gcos.^2))); Ssin = sqrt(sum(sum(Gsin.^2)));
    0031 Gcos = Gcos/Scos; Gsin = Gsin/Ssin; % l_2 norm is 1.
    0032 G = Gcos + sqrt(-1)*Gsin;  % sine and cosine pair
    0033
    0034
    0035
    0036
    0037
    0038
    0039