Home > fmri > utils > plot_img_series.m

plot_img_series

PURPOSE ^

plot_img_series(imgInfo, params)

SYNOPSIS ^

function plot_img_series(imgInfo,params)

DESCRIPTION ^

 plot_img_series(imgInfo, params)

 Uses slice_overlay to plot multiple pages of slice data, with the
 possibility of multiple data volumes per page.

 imgInfo is equivalent to the SO structure that is expected by
 slice_overlay.

 Plotting parameters
 params.maxImgPerPage - maximum number of images per page [default=4]
   .start_fignum - starting figure number [1]
   .numCol - number of columns [2]
   .rowTitleAreaHeight - proportion of row height devoted to plot titles [0.025]
   .SEPARATE_FIGS - place each page in its own figure window [0]
   .PRINT_FIGS - print the figure [0]
   .figfname - path to which to print the figure ['']
   .PLOT_INDIV_SLICES - plots each slice to its own jpeg file in a
   directory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function plot_img_series(imgInfo,params)
0002 % plot_img_series(imgInfo, params)
0003 %
0004 % Uses slice_overlay to plot multiple pages of slice data, with the
0005 % possibility of multiple data volumes per page.
0006 %
0007 % imgInfo is equivalent to the SO structure that is expected by
0008 % slice_overlay.
0009 %
0010 % Plotting parameters
0011 % params.maxImgPerPage - maximum number of images per page [default=4]
0012 %   .start_fignum - starting figure number [1]
0013 %   .numCol - number of columns [2]
0014 %   .rowTitleAreaHeight - proportion of row height devoted to plot titles [0.025]
0015 %   .SEPARATE_FIGS - place each page in its own figure window [0]
0016 %   .PRINT_FIGS - print the figure [0]
0017 %   .figfname - path to which to print the figure ['']
0018 %   .PLOT_INDIV_SLICES - plots each slice to its own jpeg file in a
0019 %   directory
0020 
0021 % December 2010, Petr Janata
0022 
0023 slice_overlay_defaults;
0024 
0025 % See if we have an image transformation structure specified
0026 if isfield(params,'tp')
0027     tp = params.tp;
0028 end
0029 
0030 % Check to see if we have necessary variables
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 % Initialize plot parameters
0047 clear global SO
0048 global SO
0049 
0050 if maxImgPerPage == 1
0051   numCol = 1;
0052 end
0053 
0054 % Figure out how many total plots we have
0055 numPlots = length(imgInfo);
0056 
0057 numPages = ceil(numPlots/maxImgPerPage);
0058     
0059 fignum = start_fignum;
0060 for ipage = 1:numPages
0061     
0062     % Calculate offset into imgInfo
0063     pageOffset = (ipage-1)*maxImgPerPage+1;
0064     
0065     % Figure out indices in imgInfo that we'll be using
0066     pageImgIdxs = pageOffset:min(pageOffset+maxImgPerPage-1,numPlots);
0067         
0068     % Create a new figure and jump through some hoops to size it
0069     % correctly so that slice_overlay will work
0070     if ipage > 1 && SEPARATE_FIGS
0071         fignum = fignum+1;
0072     end
0073         
0074     % Position the figure appropriately
0075     figure(fignum), clf
0076   set(gcf,'PaperType', PAPER_TYPE);
0077     set(gcf,'PaperPosition', [0 0 1 1], 'PaperUnits','normalized'); % create a full page
0078     set(gcf,'PaperUnits', 'points', 'Units','points');  % convert to measure we can use to set the position with
0079     set(gcf,'Position', [0 0 get(gcf,'PaperSize')]); % move the figure window on the screen and set it to correct size
0080     set(gcf,'Units','pixels'); % put things in pixels which is what slice_overlay wants
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         % Copy the img stack
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         % Specify the plot area
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         % Make the plot
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')  % do the plot
0142             
0143         % Now we need to add a title
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       % Create an axes in the title area
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 % for iplot=
0164         
0165   % If we are plotting individual slices and have only one child axes, then
0166   % try to crop the figure to the axes
0167   children = get(gcf,'children');
0168   if length(children) == 1
0169     % Get the position of the child and simply try to set the paper
0170     % position to that
0171 %    childPos = get(children,'Position');
0172 %    set(gcf,'Position',childPos)
0173 %    set(gcf,'PaperPositionMode','auto')
0174 %    set(children,'Position',[0 0 1 1], 'units', 'normalized')
0175     
0176     % To make sure that tick labels show up, set their color to black
0177     set(children,'xcolor', [0 0 0], 'ycolor', [0 0 0])
0178   end
0179   
0180     % Print the figure out to a file
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 % for ipage

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003