Home > marsbar > @maroi_image > private > my_vol_func.m

my_vol_func

PURPOSE ^

checks vol and func, returns processed image matrix or error

SYNOPSIS ^

function [img, errstr] = my_vol_func(vol, func)

DESCRIPTION ^

 checks vol and func, returns processed image matrix or error

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [img, errstr] = my_vol_func(vol, func)
0002 % checks vol and func, returns processed image matrix or error
0003 %
0004 % $Id$
0005 
0006 if nargin < 1
0007   error('Need object or vol struct');
0008 end
0009 if isa(vol, 'maroi_image')
0010   [vol def_func] = deal(vol.vol, vol.func);
0011 else
0012   def_func = '';
0013 end
0014 if nargin < 2
0015   func = '';
0016 end
0017 if isempty(func), func = def_func; end
0018 
0019 img = [];
0020 errstr = '';
0021 
0022 if ischar(vol) % filename passed?
0023   try 
0024     vol = spm_vol(vol);
0025   catch
0026     errstr = lasterr;
0027     return
0028   end
0029 end
0030 
0031 if isempty(vol)
0032   errstr = 'vol is empty';
0033   return
0034 end
0035 if ~isstruct(vol)
0036   errstr = 'vol is not struct';
0037   return
0038 end
0039 if ~isfield(vol, 'fname')
0040   errstr = 'vol does not contain fname field';
0041   return
0042 end
0043   
0044 try 
0045   % load image into matrix
0046   img = spm_read_vols(vol);
0047 catch
0048   errstr = lasterr;
0049   return
0050 end
0051 
0052 % apply and check function if passed
0053 if ~isempty(func)
0054   sz = size(img);
0055   try 
0056     img = double(eval(func));
0057   catch
0058     errstr = lasterr;
0059     img = [];
0060     return
0061   end
0062   
0063   % check that the image has not changed size
0064   sz2 = size(img);
0065   if length(sz) ~= length(sz2) | any(sz ~= sz2)
0066     img = [];
0067     errstr = sprintf('Bad function "%s" - the image has changed size',...
0068              func);
0069   end
0070 end

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