
disp(['===============> Getting parameters, mex-c code, and training images']);
mkdir('working'); % working directory to store .mat files. 
mkdir('output'); % directory that contains output from the code. 

%% parameters for the outer square bounding box
category = 'Egret';
outerBBSize = 200; % the size of the bounding square box which holds the template lattice
templateSize = floor(.5 + [outerBBSize outerBBSize]); % object template size
%% parameters for Gabor filters
numScale = 1;
scales = [1]; % scales of Gabor wavelets
numOrient = 16;  % number of orientations
saturation = 6.; % saturation level for sigmoid transformation
%% parameters for exponential model
binSize = .2;  % binsize for computing histogram of q()
numStoredPoint = 50; % number of stored lambda values
spacing = .1; % spacing between two adjacent points
%% parameters for normalization
localOrNot = 1; % if we use local normalization or not. If not, set it to -1 
localHalfx1 = 20; localHalfy1 = 20; % the half range for local normalization, has to be quite large
windowNormalizeOrNot = -1; % whether normalize within the scanning window in detection 
if (localOrNot>0)
    windowNormalizeOrNot = -1;
end % if we use local normalization, we should not use window normalization in detection
thresholdFactor = .01;  % divide the response by max(average, maxAverage*thresholdFactor)
%% parameters for active basis
starting = 1; % initilize by single image learning from I{starting}
epsilon = .1; % allowed correlation between selected Gabors 
subsample = 1; % subsample in computing MAX1 maps
locationShiftLimit = 2; % shift in normal direction = locationShiftLimit*subsample pixels
orientShiftLimit = 1; % shift in orientation
numElement1 = 20; % number of Gabors in active basis at the first scale
LambdaThreshold = 0.6; % the threshold to cut off selected Gabors
numIt = 3; % number of EM-type iterations (alternative Find and Learn)
%% read in positive images
sizeTemplatex = templateSize(1);
sizeTemplatey = templateSize(2);
halfTemplatex = floor(sizeTemplatex/2);
halfTemplatey = floor(sizeTemplatey/2);
imageFolder = 'positiveImage'; % folder of training images  
imageName = dir([imageFolder '/*.jpg']);
numImage = size(imageName, 1); % number of training images 
Ioriginal = cell(1, numImage);
for img = 1 : numImage
    tmpIm = imread([imageFolder '/' imageName(img).name]); 
    if size(tmpIm,3) == 3
        tmpIm = rgb2gray(tmpIm);
    end

    sx = size(tmpIm,1); sy = size(tmpIm,2);
    if sx >= sy
        newSx = outerBBSize;
        newSy = floor(.5+outerBBSize*sy/sx);
    else
        newSy = outerBBSize;
        newSx = floor(.5+outerBBSize*sx/sy);
    end
    tmpIm = imresize(tmpIm,[newSx,newSy],'nearest');
    
    % Note: now, to get outerBBsize from tmpIm, we only need to compute max(size(tmpIm)); 
    
    Ioriginal{img} = single(tmpIm);
    J0 = Ioriginal{img};
    multipleResolutionImageName = ['working/multipleResolutionImage' num2str(img)]; 
    save(multipleResolutionImageName, 'J0');
end

%% part locations and deformations
partSize = 100;
PartLocX = 1:partSize/4:templateSize(1)-partSize+1;
PartLocY = 1:partSize/4:templateSize(2)-partSize+1;
partLocRange = partSize/4;
partInhibitionMethod = 'boundingbox'; % the method of local inhibition for adjacent partial templates 
partGainThreshold = 45; % the selection threshold of partial templates to compose into an Active Plate 
zipfilename = sprintf('AP_%s_20101004.zip',category);
save('Config.mat','partSize','PartLocX','PartLocY','partLocRange','starting',...
    'category','outerBBSize','templateSize','numOrient',...
    'numElement1','locationShiftLimit','orientShiftLimit','numImage','category','numIt','zipfilename',...
    'LambdaThreshold','partGainThreshold','partInhibitionMethod');
clear Ioriginal

