# SetTemplateParameters

## PURPOSE

SetTemplateParameters - Set parameters for the image template.

## SYNOPSIS

function SetTemplateParameters

## DESCRIPTION

     SetTemplateParameters - Set parameters for the image template.

       Parameters are hard coded in this .m file.
       Please directly edit the code.

       Gabor feature parameters:

             Scales and the corresponding filter sizes
             0.2: 5 * 5
             0.3: 9 * 9
             0.4: 11 * 11
             0.6: 15 * 15
             0.8: 21 * 21
             1.2: 29 * 29
             1.6: 39 * 39

## CROSS-REFERENCE INFORMATION

This function calls:

- GaborFilter GaborFilter - generate Gabor filter at fixed scale and orientation.

This function is called by:

## SOURCE CODE

    0001 function SetTemplateParameters
    0002 % SetTemplateParameters - Set parameters for the image template.
    0003 %
    0004 %   Parameters are hard coded in this .m file.
    0005 %   Please directly edit the code.
    0006 %
    0007 %
    0008 %   Gabor feature parameters:
    0009 %
    0010 %         Scales and the corresponding filter sizes
    0011 %         0.2: 5 * 5
    0012 %         0.3: 9 * 9
    0013 %         0.4: 11 * 11
    0014 %         0.6: 15 * 15
    0015 %         0.8: 21 * 21
    0016 %         1.2: 29 * 29
    0017 %         1.6: 39 * 39
    0018
    0019 addpath('common');
    0020
    0021 %% Feature parameters
    0022
    0023 %
    0024 % Use single precision numbers to save memory.
    0025 %
    0026 SinglePrecision = 1;
    0027
    0028 %
    0029 % Gabor scale, #orientations
    0030 %
    0031 GaborScale = single([0.2, 0.3, 0.4, 0.6, 0.8, 1.2, 1.6]);
    0032 nGaborScale = length(GaborScale);
    0033 nGaborOri = 16;
    0034 GaborFilter = cell(nGaborScale*nGaborOri,1);
    0035 GaborSymbol = cell(nGaborScale*nGaborOri,1);
    0036 for iScale = 1:nGaborScale
    0037     [ GaborFilter( (iScale-1)*nGaborOri + (1:nGaborOri) ) ...
    0038         GaborSymbol( (iScale-1)*nGaborOri + (1:nGaborOri) ) ]...
    0039         = makefilter(GaborScale(iScale), nGaborOri, SinglePrecision);
    0040 end
    0041
    0042 %
    0043 % Correlation betweeen Gabor filters. Used for local inhibition.
    0044 %
    0045 CorrGabor = cell(nGaborOri*nGaborScale, nGaborOri*nGaborScale);
    0046 GaborOverlapTolerance = 0.1;
    0047 for iF = 1:nGaborOri*nGaborScale
    0048     hi = (size(GaborFilter{iF}, 1) - 1) / 2;            % half size of filter iF
    0049     for jF = 1:nGaborOri*nGaborScale
    0050         hj = (size(GaborFilter{jF}, 1) - 1) / 2;        % half size of filter jF
    0051         I = zeros(2*(hi+hj)+1)+sqrt(-1)*zeros(2*(hi+hj)+1);
    0052         I((hj+1):(hj+2*hi+1), (hj+1):(hj+2*hi+1)) = GaborFilter{iF}; % put GaborFilter{iF} at the center
    0053         % convolve GaborFilter{iF} by GaborFilter{jF}, 4 real-imaginary combinations
    0054         rr = filter2(real(GaborFilter{jF}), real(I), 'same');
    0055         ri = filter2(real(GaborFilter{jF}), imag(I), 'same');
    0056         ir = filter2(imag(GaborFilter{jF}), real(I), 'same');
    0057         ii = filter2(imag(GaborFilter{jF}), imag(I), 'same');
    0058         if SinglePrecision > 0
    0059             CorrGabor{iF, jF} = single( ((rr.*rr + ri.*ri + ir.*ir + ii.*ii)<GaborOverlapTolerance)*1.0 );
    0060         else
    0061             CorrGabor{iF, jF} = double( ((rr.*rr + ri.*ri + ir.*ir + ii.*ii)<GaborOverlapTolerance)*1.0 );
    0062         end
    0063         % CorrGabor{i,j} is how filter i at (0,0) inhibites filter j at locations overlapping with filter i
    0064    end
    0065 end
    0066
    0067
    0068 %
    0069 % Parameter for Gabor filter responses
    0070 %
    0071 GaborSaturation = 6;
    0072
    0073 %
    0074 % Parameter for exponential model
    0075 %
    0076 binSize = .2;  % binsize for computing histogram of q()
    0077 numStoredPoint = 40; % number of stored lambda values
    0078 spacing = .05; % spacing between two adjacent points
    0079
    0080 % save
    0081 save('template_params.mat');
    0082
    0083