Home > marsbar > @maroi_image > maroi_image.m

maroi_image

PURPOSE ^

maroi_image - class constructor

SYNOPSIS ^

function [o, others] = maroi_image(params)

DESCRIPTION ^

 maroi_image - class constructor
 inputs [defaults]
  params  - filename, for image defining ROI
            or spm vol struct (see spm_vol)

 This ROI type is a child of the maroi_matrix type.  maroi_image ROIs are
 static, in that they are defined by a particular image, and optionally, a
 function to apply to the image.  If the image changes, so will the ROI.
 However, the ROI will not change the image, so, if any changes are made to
 the ROI, such as flips, setting of the data directly using the matrixdata
 function of maroi_matrix, etc, then the ROI automatically become a
 maroi_matrix type, and is detached from the image.

 Note that the image is referenced by an absolute path, so if the path
 to the image changes, loading the ROI will fail.  Reassociate the image
 with an ROI using the vol method.

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [o, others] = maroi_image(params)
0002 % maroi_image - class constructor
0003 % inputs [defaults]
0004 %  params  - filename, for image defining ROI
0005 %            or spm vol struct (see spm_vol)
0006 %
0007 % This ROI type is a child of the maroi_matrix type.  maroi_image ROIs are
0008 % static, in that they are defined by a particular image, and optionally, a
0009 % function to apply to the image.  If the image changes, so will the ROI.
0010 % However, the ROI will not change the image, so, if any changes are made to
0011 % the ROI, such as flips, setting of the data directly using the matrixdata
0012 % function of maroi_matrix, etc, then the ROI automatically become a
0013 % maroi_matrix type, and is detached from the image.
0014 %
0015 % Note that the image is referenced by an absolute path, so if the path
0016 % to the image changes, loading the ROI will fail.  Reassociate the image
0017 % with an ROI using the vol method.
0018 %
0019 % $Id$
0020   
0021 myclass = 'maroi_image';
0022 defstruct = struct('vol', [],'func', '');
0023 
0024 if nargin < 1
0025   params = [];
0026 end
0027 if isa(params, myclass)
0028   o = params;
0029   return
0030 end
0031 
0032 % check for filename;
0033 if ischar(params)
0034   params = struct('vol', spm_vol(params));
0035 end
0036 % check for vol struct
0037 if isfield(params, 'fname')
0038   params.vol = params;
0039 end
0040 
0041 % fill with defaults
0042 pparams = mars_struct('ffillmerge', defstruct, params);
0043 
0044 if ~isempty(pparams.vol) % check for attempt at create empty object
0045 
0046   % check and process vol and func
0047   [img errstr] = my_vol_func(pparams.vol, pparams.func);
0048   if isempty(img), error(errstr); end
0049 
0050   % prepare for maroi_matrix creation
0051   pparams.dat = img;
0052   pparams.mat = pparams.vol.mat;
0053 
0054   % fill source information if empty
0055   if ~isfield(pparams, 'source') | isempty(pparams.source)
0056     pparams.source = maroi('filename',pparams.vol.fname);
0057   end
0058 end
0059 
0060 % umbrella object, parse out fields for (this object and children)
0061 [uo, pparams] = maroi_matrix(pparams);
0062 
0063 % reparse parameters into those for this object, children
0064 [pparams, others] = mars_struct('split', pparams, defstruct);
0065 
0066 o = class(pparams, myclass, uo);
0067 return

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