Home > marsbar > @maroi > get_marsy.m

get_marsy

PURPOSE ^

gets data in ROIs from images

SYNOPSIS ^

function marsY = get_marsy(varargin)

DESCRIPTION ^

 gets data in ROIs from images
 FORMAT marsY = get_marsy(roi1 [, roi2 [, roi3...]], VY, sumfunc, flags)

 roi1, roi2... - ROI objects
                   This rather arcane call is needed because matlab
                   does not allow different object types in an array
 VY            - array of SPM vol structs, or image names, or SPM design
 sumfunc       - one of 'mean', 'median', 'eigen1', 'wtmean'  to summarize
                   data in the ROIs
 flags         - none or more of
                   'v' - selects verbose output to matlab console

 Returns
 marsY      - MarsBaR data object

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function marsY = get_marsy(varargin)
0002 % gets data in ROIs from images
0003 % FORMAT marsY = get_marsy(roi1 [, roi2 [, roi3...]], VY, sumfunc, flags)
0004 %
0005 % roi1, roi2... - ROI objects
0006 %                   This rather arcane call is needed because matlab
0007 %                   does not allow different object types in an array
0008 % VY            - array of SPM vol structs, or image names, or SPM design
0009 % sumfunc       - one of 'mean', 'median', 'eigen1', 'wtmean'  to summarize
0010 %                   data in the ROIs
0011 % flags         - none or more of
0012 %                   'v' - selects verbose output to matlab console
0013 %
0014 % Returns
0015 % marsY      - MarsBaR data object
0016 %
0017 % $Id$
0018 
0019 for r = 1:nargin
0020   if ~isa(varargin{r}, 'maroi')
0021     break
0022   end
0023 end
0024 rlen = r - 1;
0025 roi_array = varargin(1:rlen);
0026 
0027 narg_left = nargin - rlen;
0028 if narg_left < 1
0029   VY = [];
0030 else
0031   VY = varargin{r};
0032 end
0033 if isempty(VY), error('Need images to extract from'); end
0034 if narg_left < 2
0035   sumfunc = '';
0036 else
0037   sumfunc = varargin{r+1};
0038 end
0039 if isempty(sumfunc), error('Need summary function'); end
0040 if narg_left < 3
0041   flags = '';
0042 else
0043   flags = varargin{r+2};
0044 end
0045 if isempty(flags), flags = ' '; end
0046 vf = any(flags == 'v');
0047 
0048 % images can come from a design
0049 des_summary = 'None';
0050 if isa(VY, 'mardo')
0051   if ~has_images(VY)
0052     error('This design does not contain images');
0053   end
0054   D  = VY;
0055   VY = get_images(VY);
0056 else
0057   D  = [];
0058 end
0059 % or be filenames
0060 if ischar(VY)
0061   if vf, fprintf('%-40s: ','Mapping files');  end
0062   VY = spm_vol(VY);
0063   if vf, fprintf('%30s\n','...done'); end
0064 end
0065 
0066 if vf, fprintf('%-40s: %30s','Fetching data',' '); end
0067 rlen = length(roi_array);
0068 rno = 0;
0069 for r = 1:rlen
0070   if vf
0071     fprintf('%s%30s',...
0072         repmat(sprintf('\b'),1,30),...
0073         sprintf('%4d/%-4d',r, rlen));
0074   end
0075   o = roi_array{r};
0076   [y vals vXYZ mat]  = getdata(o, VY);
0077   [ny nvals] = size(y);
0078   if isempty(y)
0079     if vf, fprintf('\n'); end
0080     warning(sprintf('No valid data for roi %d (%s)', r, label(o)));
0081     if vf & (r < rlen), fprintf('%-40s: %30s','Fetching data',' '); end
0082   else
0083     rno = rno + 1;
0084     % get data for regions
0085     if all(vals == 1)
0086       vals = [];
0087     end
0088     r_data{rno} = y;
0089     r_info{rno} = struct(...
0090         'name', label(o),...
0091         'descrip', descrip(o),...
0092         'weights', vals,...
0093         'info', struct('file', source(o)),...
0094         'vXYZ', vXYZ,...
0095         'mat', mat);
0096     if rno < 2,  lbl = label(o); else lbl = [lbl ' & ' label(o)]; end
0097   end
0098 end
0099 if vf, fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done'); end
0100 
0101 if rno == 0
0102   marsY = [];
0103   return;
0104 end
0105 
0106 s_info = struct(...
0107     'sumfunc', sumfunc, ...
0108     'descrip', ['Data from ' lbl],...
0109     'info', struct('VY', VY));
0110 
0111 % Fill any available information from design if passed
0112 if ~isempty(D)
0113   s_info.info.des_summary = summary(D);
0114   s_info.info.TR          = tr(D);
0115   s_info.block_rows       = block_rows(D);
0116 end
0117 
0118 marsY = marsy(r_data, r_info, s_info);

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019