Home > bioelectromagnetism > avw_roi.m

avw_roi

PURPOSE ^

avw_roi - extract a region of interest from avw.img

SYNOPSIS ^

function [roi] = avw_roi(avw,position,shape)

DESCRIPTION ^

 avw_roi - extract a region of interest from avw.img

 [roi] = avw_roi(avw,[position],[shape])

 avw - the analyze struct with avw.hdr and avw.img

 position - the centroid voxel for the roi, the default is the volume
 center.  For example, 256^3 voxels would have a center at [128,128,128].

 shape - the shape of the roi.  This is a struct:

            shape.type = 'block'
            shape.size = [X,Y,Z] voxels

 The default is 'block' and the whole volume.  Note that the block type
 encompasses any 3D square or rectangle.  Further development may include
 sphere and ellipse shapes, with mm parameters.

 roi.index - The volume indices into avw.img that comprise the region of
 interest (roi).
 roi.value - The values at the voxels in avw.img that comprise the roi.
 The returned value can be used with avw_stats.  The default is the entire
 volume, ie: roi.value = avw.img;

 see also:  avw_stats

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [roi] = avw_roi(avw,position,shape)
0002 
0003 % avw_roi - extract a region of interest from avw.img
0004 %
0005 % [roi] = avw_roi(avw,[position],[shape])
0006 %
0007 % avw - the analyze struct with avw.hdr and avw.img
0008 %
0009 % position - the centroid voxel for the roi, the default is the volume
0010 % center.  For example, 256^3 voxels would have a center at [128,128,128].
0011 %
0012 % shape - the shape of the roi.  This is a struct:
0013 %
0014 %            shape.type = 'block'
0015 %            shape.size = [X,Y,Z] voxels
0016 %
0017 % The default is 'block' and the whole volume.  Note that the block type
0018 % encompasses any 3D square or rectangle.  Further development may include
0019 % sphere and ellipse shapes, with mm parameters.
0020 %
0021 % roi.index - The volume indices into avw.img that comprise the region of
0022 % interest (roi).
0023 % roi.value - The values at the voxels in avw.img that comprise the roi.
0024 % The returned value can be used with avw_stats.  The default is the entire
0025 % volume, ie: roi.value = avw.img;
0026 %
0027 % see also:  avw_stats
0028 %
0029 
0030 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
0031 
0032 % Licence:  GNU GPL, no express or implied warranties
0033 % History:  08/2003, Darren.Weber_at_radiology.ucsf.edu
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 
0038 
0039 version = '[$Revision: 1.1 $]';
0040 fprintf('\nAVW_ROI [v%s]\n',version(12:16));  tic;
0041 
0042 if ~exist('avw','var'),
0043   doc avw_roi;
0044   msg = sprintf('...no input avw\n');
0045   error(msg);
0046 elseif isempty(avw),
0047   doc avw_roi;
0048   msg = sprintf('...empty input avw\n');
0049   error(msg);
0050 end
0051 
0052 if ~exist('shape','var'),
0053   fprintf('...no input shape, using the whole volume\n');
0054   roi.value = avw.img;
0055   return
0056 else
0057   if ~isfield(shape,'type'),
0058     fprintf('...no input shape.type, using block\n');
0059     shape.type = 'block';
0060   end
0061   if ~isfield(shape,'size'),
0062     fprintf('...no input shape.size, using [5,5,5]\n');
0063     shape.size = [ 5,5,5 ];
0064   end
0065 end
0066 
0067 s = size(avw.img);
0068 xdim = s(1);
0069 ydim = s(2);
0070 if length(s) > 2, zdim = s(3);
0071 else              zdim = 1;
0072 end
0073 
0074 if ~exist('position','var'),
0075   fprintf('...no input position, using volume center\n');
0076   position = [1,1,1];
0077   if xdim > 1, position(1) = floor(xdim/2); end
0078   if ydim > 1, position(2) = floor(ydim/2); end
0079   if zdim > 1, position(3) = floor(zdim/2); end
0080 end
0081 
0082 
0083 
0084 switch shape.type,
0085   
0086   case 'block',
0087     
0088     fprintf('...defining [%d,%d,%d] ''block'' region of interest.\n',...
0089       shape.size(1),shape.size(2),shape.size(3));
0090     
0091     xrange = floor(shape.size(1) / 2);
0092     yrange = floor(shape.size(2) / 2);
0093     zrange = floor(shape.size(3) / 2);
0094     
0095     xroi = [ position(1) - xrange, position(1) + xrange ];
0096     if xroi(1) < 1, xroi(1) = 1; end
0097     if xroi(2) > xdim, xroi(2) = xdim; end
0098     roi_xindex = xroi(1):xroi(2);
0099     
0100     yroi = [ position(2) - yrange, position(2) + yrange ];
0101     if yroi(1) < 1, yroi(1) = 1; end
0102     if yroi(2) > ydim, yroi(2) = ydim; end
0103     roi_yindex = yroi(1):yroi(2);
0104     
0105     zroi = [ position(3) - zrange, position(3) + zrange ];
0106     if zroi(1) < 1, zroi(1) = 1; end
0107     if zroi(2) > zdim, zroi(2) = zdim; end
0108     roi_zindex = zroi(1):zroi(2);
0109     
0110     roi.index = [roi_xindex;roi_yindex;roi_zindex];
0111     roi.value = avw.img(roi_xindex,roi_yindex,roi_zindex);
0112     
0113   case 'sphere',
0114     
0115     %fprintf('...defining [%d,%d,%d] ''sphere'' region of interest.\n',...
0116     %  position(1),position(2),position(3));
0117     
0118     fprintf('...sorry, sphere shape calculations are not yet available\n');
0119     roi.index = [];
0120     roi.value = [];
0121     
0122     %Rroi = shape.size(1);
0123     
0124     
0125   otherwise,
0126     
0127     msg = sprintf('...no support for shape.type = %s',shape.type);
0128     error(msg);
0129     
0130 end
0131 
0132 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003