# OutputActiveBasisTemplate

## PURPOSE

OutputActiveBasisTemplate - Generates figures and captions.

## SYNOPSIS

function OutputActiveBasisTemplate(category)

## DESCRIPTION

     OutputActiveBasisTemplate - Generates figures and captions.

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