0001 function plot_img_series(imgInfo,params)
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 
0022 
0023 slice_overlay_defaults;
0024 
0025 
0026 if isfield(params,'tp')
0027     tp = params.tp;
0028 end
0029 
0030 
0031 try maxImgPerPage = params.maxImgPerPage; catch maxImgPerPage = 4; end
0032 try SEPARATE_FIGS = params.SEPARATE_FIGS; catch SEPARATE_FIGS = 0; end
0033 try start_fignum = params.start_fignum; catch start_fignum = 1; end
0034 try numCol = params.numCol; catch numCol = 2; end
0035 try rowTitleAreaHeight = params.rowTitleAreaHeight; catch rowTitleAreaHeight = 0.025; end
0036 try colScaleFactor = params.colScaleFactor; catch colScaleFactor = 0.95; end
0037 try PRINT_FIGS = params.PRINT_FIGS; catch PRINT_FIGS = 0; end
0038 try figfname = params.figfname; catch figfname = ''; end
0039 try PLOT_INDIV_SLICES = params.PLOT_INDIV_SLICES; catch PLOT_INDIV_SLICES = 0; end
0040 try PAPER_TYPE = params.paperType; catch PAPER_TYPE = 'usletter'; end
0041 
0042 numRow = ceil(maxImgPerPage/numCol);
0043 
0044 global_tp = tp;
0045 
0046 
0047 clear global SO
0048 global SO
0049 
0050 if maxImgPerPage == 1
0051   numCol = 1;
0052 end
0053 
0054 
0055 numPlots = length(imgInfo);
0056 
0057 numPages = ceil(numPlots/maxImgPerPage);
0058     
0059 fignum = start_fignum;
0060 for ipage = 1:numPages
0061     
0062     
0063     pageOffset = (ipage-1)*maxImgPerPage+1;
0064     
0065     
0066     pageImgIdxs = pageOffset:min(pageOffset+maxImgPerPage-1,numPlots);
0067         
0068     
0069     
0070     if ipage > 1 && SEPARATE_FIGS
0071         fignum = fignum+1;
0072     end
0073         
0074     
0075     figure(fignum), clf
0076   set(gcf,'PaperType', PAPER_TYPE);
0077     set(gcf,'PaperPosition', [0 0 1 1], 'PaperUnits','normalized'); 
0078     set(gcf,'PaperUnits', 'points', 'Units','points');  
0079     set(gcf,'Position', [0 0 get(gcf,'PaperSize')]); 
0080     set(gcf,'Units','pixels'); 
0081         
0082     SO.figure = figure(fignum);
0083     set(SO.figure,'DefaultLineLineWidth', DEFAULT_CONTOUR_WIDTH)
0084     SO.labels.format = '%+d';
0085     SO.labels.size = 0.1;
0086     SO.transform = tp.transform_types{tp.transform_idx};
0087         
0088     for iplot = 1:length(pageImgIdxs)
0089     currIdx = pageImgIdxs(iplot);
0090         
0091         
0092         SO.img = imgInfo(currIdx).img;
0093         
0094         try SO.cbar = imgInfo(currIdx).cbar; catch SO.cbar = []; end
0095         try SO.contours = imgInfo(currIdx).contours; catch SO.contours = []; end
0096         try SO.ticks = imgInfo(currIdx).ticks; catch SO.ticks.show = 0; end        
0097     try SO.white_background = imgInfo(currIdx).white_background; catch SO.white_background = 0; end
0098    
0099     if SO.white_background
0100       SO.labels.colour = [0 0 0];
0101     end
0102     
0103         
0104         rowidx = ceil(iplot/numCol);
0105         colidx = mod(iplot-1,numCol)+1;
0106             
0107         row_height = 1/numRow;
0108         height = row_height-rowTitleAreaHeight;
0109             
0110         col_margin = ((1-colScaleFactor)/numCol)/2;
0111         col_width = 1/numCol;
0112         width = col_width-col_margin*2;
0113             
0114         bottom = 1-rowidx*row_height;
0115         left = (colidx-1)/numCol+col_margin;
0116             
0117         
0118     if isfield(imgInfo(currIdx), 'tp')
0119       tp = imgInfo(currIdx).tp;
0120     else
0121       tp = global_tp;
0122     end
0123     
0124     if ~isempty(tp.non_contig_slices)
0125       SO.slices = tp.non_contig_slices;
0126     else
0127       if length(tp.slice_ranges) > 1
0128         SO.slices = ...
0129           tp.slice_ranges(tp.transform_idx,1):sign(diff(tp.slice_ranges(tp.transform_idx,:)))*tp.slice_skip:tp.slice_ranges(tp.transform_idx,2);
0130       else
0131         SO.slices = tp.slice_ranges;
0132       end
0133     end
0134     
0135         slice_overlay('checkso')
0136             
0137         SO.refreshf = 1;
0138         SO.clf = 0;
0139         SO.area.position = [left bottom width height];
0140         SO.area.units = 'normalized';
0141         slice_overlay('display')  
0142             
0143         
0144         try 
0145             title_str = imgInfo(currIdx).title.text;
0146         catch
0147             title_str = '';
0148         end
0149         
0150         try 
0151             format_args = imgInfo(currIdx).title.format_args;
0152         catch 
0153             format_args = {};
0154         end
0155             
0156         if ~isempty(title_str)
0157       
0158       tah = axes('position', [left bottom+height width rowTitleAreaHeight], ...
0159             'visible','off');
0160             
0161             t = text(0.5, 0.25, title_str, format_args{:});
0162         end
0163     end 
0164         
0165   
0166   
0167   children = get(gcf,'children');
0168   if length(children) == 1
0169     
0170     
0171 
0172 
0173 
0174 
0175     
0176     
0177     set(children,'xcolor', [0 0 0], 'ycolor', [0 0 0])
0178   end
0179   
0180     
0181   if PLOT_INDIV_SLICES && exist(imgInfo(currIdx).fpath,'dir')
0182     transform_str = tp.transform_types{tp.transform_idx};
0183 
0184     [fpath,fstub] = fileparts(imgInfo(currIdx).fpath);
0185     switch transform_str
0186       case 'coronal'
0187         slice_plane = 'y';
0188       case 'axial'
0189         slice_plane = 'z';
0190       otherwise
0191         slice_plane = 'x';
0192     end
0193     figfname = fullfile(imgInfo(currIdx).fpath, sprintf('%s_%s=%dmm.png',fstub, slice_plane,tp.slice_ranges));
0194     append_str = '';
0195     ftype_str = '-dpng';
0196   end 
0197   
0198     if PRINT_FIGS && ~isempty(figfname)
0199     if ~PLOT_INDIV_SLICES
0200       ftype_str = '-dpsc';
0201       if ipage == 1
0202         fprintf('Printing plots to %s\n', figfname);
0203         append_str = '';
0204       else
0205         append_str = '-append';
0206       end
0207     end
0208         set(gcf,'PaperPosition',[0 0 get(gcf,'PaperSize')]);
0209         print(figfname, ftype_str, append_str);
0210     end
0211 end