% StartFromHere - The entry point of this project.
%
%   StartFromHere learns active basis templates and adaboost strong classifiers  
%   for all image categories under the "image" folder. It generates figures
%   needed for the project report and the corresponding latex into the "document" folder. 

%% compilation
cd common
mex ClocalNormalizeDouble.c
mex Chistog.c
mex CcomputeMAX1.c
mex Ctransform.c
cd ../activebasis
mex Clearn.c
cd ../adaboost
mex adaboostLearning.c
mex adaboostTesting.c
cd ..

%% obtain natural statistics
if ~exist('result/natural_stat.mat','file')
    cd('common');
    GetNaturalStat;
    cd ..
end


%% template parameters per category
SetTemplateParameters;
cd common

%% collect negative patches for adaboost
PrepareNegativeImagePatches;
cd ..

disp('parameters set');

%% learning templates by active basis model and by adaboost
folders = {'cow','deer','catHead','wolfHead','horse','butterfly'};
for iFolder = 1:length(folders)
    % learn and save the model to "result" folder
    LearnActiveBasisTemplate(folders{iFolder});
    LearnAdaboostTemplate(folders{iFolder});
end

%% generate figures
addpath('common');
folders = {'cow','deer','catHead','wolfHead','horse','butterfly'};
for iFolder = 1:length(folders)
    % generate latex files with figures and captions
    OutputActiveBasisTemplate(folders{iFolder});
    OutputAdaboostTemplate(folders{iFolder});
end

%% generate latex text
% folders = {'zebra','women_model1','cow','pigeon','car','lion', 'deer', 'elephant_frontal', 'elephant_side', 'giraff', 'head_shoulder'};
folders = {'cow','deer','catHead','wolfHead','horse','butterfly'};
% generate latex files with figures and captions
GenerateFigureCaption(folders);



