0001 function [roi] = avw_roi(avw,position,shape)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
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
0116
0117
0118 fprintf('...sorry, sphere shape calculations are not yet available\n');
0119 roi.index = [];
0120 roi.value = [];
0121
0122
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