# OutputAdaboostTemplate

## PURPOSE

OutputAdaboostTemplate - Generates figures for adaboost strong classifier.

## SYNOPSIS

function OutputAdaboostTemplate(category)

## DESCRIPTION

     OutputAdaboostTemplate - Generates figures for adaboost strong classifier.

## CROSS-REFERENCE INFORMATION

This function calls:

- Outepspng Outepspng - Generate png and eps figures.

This function is called by:

- StartFromHere StartFromHere - The entry point of this project.

## SOURCE CODE

    0001 function OutputAdaboostTemplate(category)
    0002 % OutputAdaboostTemplate - Generates figures for adaboost strong classifier.
    0003 %
    0004
    0005 % load the template
    0006 matFile = sprintf('result/%s/adaboost_model.mat',category);
    0007 load(matFile,'symbolicTemplate','deformedTemplate','scoresPos','templateSize');
    0008 sizex = templateSize(1); sizey = templateSize(2);
    0009
    0010 % load example images
    0011 rootFolder = pwd;
    0012 imageNames = [];
    0013 imageNames = [imageNames; dir(sprintf('%s/image/%s/*.jpg',rootFolder,category))];
    0014 imageNames = [imageNames; dir(sprintf('%s/image/%s/*.bmp',rootFolder,category))];
    0015 imageNames = [imageNames; dir(sprintf('%s/image/%s/*.png',rootFolder,category))];
    0016 numImage = length(imageNames);
    0017 I = cell(numImage,1);
    0018 for i = 1:numImage
    0019     I{i} = imread( sprintf('%s/image/%s/%s',rootFolder,category,imageNames(i).name) );
    0020     if size(I{i},3) == 3
    0021         I{i} = rgb2gray(I{i});
    0022     end
    0023     I{i} = double(imresize(I{i},templateSize,'nearest'));
    0024 end
    0025
    0026 K = numImage; bx = 10; by = 10; cc = 3;
    0027 [SUM2scoresort, ind] = sort(scoresPos);
    0028 col = 5; row = floor(K/col)+1;
    0029 Iout = zeros(row*sizex+(row-1)*(2*bx+cc), 2*col*sizey+(col-1)*(2*by+cc),3)+255;
    0030 towrite =  double( symbolicTemplate );
    0031 towrite = (255 * (towrite-min(towrite(:)))/(max(towrite(:))-min(towrite(:))));
    0032 Iout(1:sizex, 1:sizey, :) = towrite;
    0033 i = -1;
    0034 for r = 1 : row
    0035     for c = 1 : col
    0036         i = i+1;
    0037         if ((i>=1)&&(i<=K))
    0038             towrite = I{ind(numImage-i+1)};
    0039             towrite = (255 * (towrite-min(towrite(:)))/(max(towrite(:))-min(towrite(:))));
    0040             Iout((r-1)*sizex+1+(r-1)*(2*bx+cc): r*sizex+(r-1)*(2*bx+cc), (c-1)*2*sizey+1+(c-1)*(2*by+cc): (c-1)*2*sizey+sizey+(c-1)*(2*by+cc), :) = repmat(towrite,[1 1 3]);
    0041             towrite = double( deformedTemplate{ind(numImage-i+1)} );
    0042             towrite = (255 * (towrite-min(towrite(:)))/(max(towrite(:))-min(towrite(:))));
    0043             Iout((r-1)*sizex+1+(r-1)*(2*bx+cc) : r*sizex+(r-1)*(2*bx+cc), (c-1)*2*sizey+sizey+(c-1)*(2*by+cc)+1 : (c-1)*2*sizey+sizey+(c-1)*(2*by+cc)+sizey, :) = towrite;
    0044         end
    0045     end
    0046 end
    0047 for r = 1 : row-1
    0048   Iout(r*sizex+(r-1)*(2*bx+cc)+bx+1:r*sizex+(r-1)*(2*bx+cc)+bx+cc, :, :) = 0;
    0049 end
    0050 for c = 1 : col-1
    0051   Iout(:, c*(sizey*2)+(c-1)*(2*by+cc)+by+1:c*(sizey*2)+(c-1)*(2*by+cc)+by+cc, :) = 0;
    0052 end
    0053 Iout = uint8(Iout);
    0054 Outepspng(Iout, sprintf('%s/result/%s/adaboost_figure', rootFolder, category));
    0055
    0056
    0057