# GenerateLatex

## PURPOSE

GenerateLatex - Generate a simple latex file together with a folder of eps figures

## SYNOPSIS

This is a script file.

## DESCRIPTION

     GenerateLatex - Generate a simple latex file together with a folder of eps figures
       with detection results.

## CROSS-REFERENCE INFORMATION

This function calls:

- displayImages displayImage - display a set of images of the same size (bx, by) on

This function is called by:

## SOURCE CODE

    0001 % GenerateLatex - Generate a simple latex file together with a folder of eps figures
    0002 %   with detection results.
    0003
    0004 addpath common
    0005
    0006 Iname = {'pelican 2_big.jpg','pelican3.jpg',...
    0007     'pelican4.jpg','pelican5.jpg','pelican6.jpg',...
    0008     'pelican7.jpg','pelican8.jpg','pelican9.jpg',...
    0009     'pelican10.jpg'};
    0010 Iname_pelican = Iname;
    0011 imScale = [0.25 0.4 0.4 0.4 ...
    0012     0.22 0.36 0.5 0.4 0.3];
    0013
    0014 category = 'pelican';
    0015 overlay_pelican = cell(length(imScale),1);
    0016 j_detection = 1;
    0017 for i = 1:length(imScale)
    0018     load(sprintf('result/%s/detectionResult%d_%s.mat',category,j_detection,Iname{i}),...
    0019                 'im','mask','S3Map','M2Map');
    0020     overlay_pelican{i} = im + 400 * mask;
    0021 end
    0022
    0023 Iname = {'l1.jpg','l2.jpg','l3.jpg','l4.jpg','l5.jpg',...
    0024     'l6.jpg','l7.jpg','l8.jpg','l9.jpg','l10.jpg',...
    0025     'l11.jpg','l12.jpg','l13.jpg','l14.jpg','l15.jpg',...
    0026     'l16.jpg','l17.jpg','l18.jpg','l19.jpg','l20.jpg',...
    0027     'l21.jpg', 'l22.jpg','l23.jpg','l24.jpg','l25.jpg',...
    0028     'l26.jpg','l27.jpg','l28.jpg','l29.jpg','l30.jpg',...
    0029     'l4_dup.jpg', 'l12_dup.jpg', 'l12_dup2.jpg'};
    0030 Iname_egret = Iname;
    0031 imScale = [1.2 1.2 1 2 1,...
    0032     1 1.2 0.9 0.9 1,...
    0033     0.95 1 1.1 1 1,...
    0034     1.1 0.8 1.2 1.2 0.9,...
    0035     .55 .3,.3 .25 .3 ...
    0036     .3 .4,.3 .35 .3,...
    0037     1.15 1.1 1.2];
    0038 category = 'egret';
    0039 overlay_egret = cell(length(imScale),1);
    0040 j_detection = 1;
    0041 for i = 1:length(imScale)
    0042     load(sprintf('result/%s/detectionResult%d_%s.mat',category,j_detection,Iname{i}),...
    0043                 'im','mask','S3Map','M2Map');
    0044     overlay_egret{i} = im + 400 * mask;
    0045 end
    0046
    0047 %%
    0048 % selected_egret = setdiff(1:33,[6 11 12 13 16 21 23 24 25 27 28 29]);
    0049 selected_egret = setdiff(1:33,[6 7 9 11 13 16 19 20 21 23 24 25 27 28 29 30]);
    0050 selected_egret = 1:33;
    0051 selected_pelican = [7:9];
    0052 selected_pelican = 1:9;
    0053
    0054 overlay = [overlay_egret(selected_egret);overlay_pelican(selected_pelican)];
    0055 Iname = [Iname_egret(selected_egret) Iname_pelican(selected_pelican)];
    0056
    0057 frames = cell(2*length(overlay),3);
    0058 % now interleve original image with overlay
    0059 for k = 1:length(overlay)
    0060     if k <= length(selected_egret)
    0061         im = imread(sprintf('image/egret/%s',Iname{k}));
    0062         currentCategory = 'egret';
    0063     else
    0064         im = imread(sprintf('image/pelican/%s',Iname{k}));
    0065         currentCategory = 'pelican';
    0066     end
    0067
    0068     for c = 1:3
    0069         frames{2*(k-1)+1,c} = im(:,:,c); % source image
    0070         frames{2*(k-1)+2,c} = overlay{k}; % overlay
    0071     end
    0072
    0073     for c = 1:3
    0074 %         channel{c} = [im(:,:,c) , overlay{k}];
    0075         channel{c} = displayImages(frames(2*(k-1)+(1:2),c),2,size(im,1),size(im,2),...
    0076             true,0,0);
    0077     end
    0078
    0079     towrite = zeros(size(channel{1}),'uint8');
    0080     for c = 1:3
    0081         towrite(:,:,c) = channel{c};
    0082     end
    0083
    0084     figure;
    0085     imshow(towrite);
    0086     saveas(gcf,sprintf('result/%s/%s.eps',currentCategory,Iname{k}),'epsc');
    0087     close;
    0088 end
    0089
    0090 %% also generate the corresponding latex
    0091 tex_dir = 'document/latex';
    0092 if ~exist(tex_dir,'dir')
    0093     mkdir(tex_dir);
    0094 else
    0095 %     rmdir(tex_dir,'s');
    0096     mkdir(tex_dir);
    0097 end
    0098 tex_path = sprintf('%s/exp.tex',tex_dir);
    0099 tex = fopen(tex_path,'w');
    0100
    0101 tex_img_dir = 'document/latex/figure/';
    0102 if ~exist(tex_img_dir,'dir')
    0103     mkdir(tex_img_dir);
    0104 end
    0105
    0106 tmp = ['\\documentclass[11pt]{article}\n' ...
    0107     '\\usepackage{epsfig}\n'];
    0108 fprintf(tex,tmp);
    0109 fprintf(tex,'\\title{Report}\n');
    0110 fprintf(tex,'\\begin{document}\n');
    0111 fprintf(tex,'\\maketitle\n');
    0112
    0113 tmp = [''];
    0114 fprintf(tex,tmp);
    0115
    0116 % move eps figures to "<root>/document/latex/figure/"
    0117 fprintf(tex, '\n \\begin{figure}[htp] \n');
    0118 for k = 1:length(overlay)
    0119     if k <= length(selected_egret)
    0120         im = imread(sprintf('image/egret/%s',Iname{k}));
    0121         currentCategory = 'egret';
    0122     else
    0123         im = imread(sprintf('image/pelican/%s',Iname{k}));
    0124         currentCategory = 'pelican';
    0125     end
    0126
    0127     % copy eps figures to "<root>/document/tex/img/"
    0128     src = sprintf('result/%s/%s.eps',currentCategory,Iname{k});
    0129     dst = sprintf('document/latex/figure/%s_%s.eps', currentCategory,Iname{k});
    0130     copyfile(src,dst);
    0131
    0132     % output the figure and caption to tex : active basis
    0133     fprintf(tex, sprintf('\\\\psfig{figure=figure/%s_%s.eps, height=300pt }\n', currentCategory, Iname{k}));
    0134
    0135 end
    0136 tmp = '\\caption{}';
    0137 fprintf(tex, tmp);
    0138 fprintf(tex, '\\label{fig:pelican}\n');
    0139 fprintf(tex, '\\end{figure} \n');
    0140
    0141 fprintf(tex, '\\end{document} \n');
    0142 fclose(tex);