Home > marsbar > mars_build_roi.m

mars_build_roi

PURPOSE ^

builds ROIs via the SPM GUI

SYNOPSIS ^

function o = mars_build_roi

DESCRIPTION ^

 builds ROIs via the SPM GUI

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function o = mars_build_roi
0002 % builds ROIs via the SPM GUI
0003 %
0004 % $Id$
0005 
0006 o = [];  
0007 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Build ROI', 0);
0008 
0009 % get ROI type
0010 optfields = {'image','voxel', 'sphere', 'box_cw', 'box_lims'};
0011 optlabs =  {'Image', 'Voxel', 'Sphere',...
0012         'Box (centre,widths)', 'Box (ranges XYZ)'};
0013 
0014 roitype = char(...
0015     spm_input('Type of ROI', '+1', 'm',{optlabs{:} 'Quit'},...
0016           {optfields{:} 'quit'},length(optfields)+1));
0017 
0018 % For selecting images, later
0019 img_flt = mars_veropts('get_img_ext');
0020 
0021 d = [];
0022 switch roitype
0023  case 'image'
0024   imgname = spm_get(1, img_flt, 'Image defining ROI');
0025   [p f e] = fileparts(imgname);
0026   binf = spm_input('Maintain as binary image', '+1','b',...
0027                       ['Yes|No'], [1 0],1);
0028   func = '';
0029   if spm_input('Apply function to image', '+1','b',...
0030                       ['Yes|No'], [1 0],1);
0031     spm_input('img < 30',1,'d','Example function:');
0032     func = spm_input('Function to apply to image', '+1', 's', 'img');
0033   end
0034   d = f; l = f;
0035   if ~isempty(func)
0036     d = [d ' func: ' func];
0037     l = [l '_f_' func];
0038   end
0039   if binf
0040     d = [d ' - binarized'];
0041     l = [l '_bin'];
0042   end
0043   o = maroi_image(struct('vol', spm_vol(imgname), 'binarize',binf,...
0044              'func', func));
0045   
0046   % convert to matrix format to avoid delicacies of image format
0047   o = maroi_matrix(o);
0048   
0049  case 'voxel'
0050   not_donef = 1;
0051   while not_donef
0052     XYZ = spm_input('Coordinate(s)', '+1', 'e', []);
0053     if size(XYZ,1) == 1, XYZ = XYZ'; end
0054     if size(XYZ,1) ~= 3, warning('Need 3xN or Nx3 matrix'); 
0055     else not_donef = 0; end
0056   end
0057   v = char(spm_input('Coordinate(s) in','+1','b','mm|voxels',{'mm','vox'}, 1));
0058   spopts = {'spacebase','image'};
0059   splabs =  {'Base space for ROIs','From image'};
0060   spo  = spm_input('Space for voxel ROI', '+1', 'm',splabs,...
0061            spopts, 1);
0062   switch char(spo)
0063    case 'spacebase'
0064     sp = maroi('classdata', 'spacebase');
0065    case 'image'
0066     img = spm_get([0 1], img_flt, 'Image defining space');
0067     if isempty(img),return,end
0068     sp = mars_space(img);
0069   end
0070   o = maroi_pointlist(struct('XYZ', XYZ, 'mat', sp.mat), v);
0071   if size(XYZ, 2) > 1
0072     pos = c_o_m(o); coord_lbl = 'C.o.M.';
0073   else
0074     pos = XYZ; coord_lbl = 'coordinate';
0075   end
0076   d = sprintf('points; %s (%s) [%0.1f %0.1f %0.1f]',coord_lbl,v,pos);
0077   l = sprintf('points_%s_%s_%0.0f_%0.0f_%0.0f',coord_lbl,v,pos);
0078  case 'sphere'
0079   c = spm_input('Centre of sphere (mm)', '+1', 'e', [], 3); 
0080   r = spm_input('Sphere radius (mm)', '+1', 'r', 10, 1);
0081   d = sprintf('%0.1fmm radius sphere at [%0.1f %0.1f %0.1f]',r,c);
0082   l = sprintf('sphere_%0.0f-%0.0f_%0.0f_%0.0f',r,c);
0083   o = maroi_sphere(struct('centre',c,'radius',r));
0084  case 'box_cw'
0085   c = spm_input('Centre of box (mm)', '+1', 'e', [], 3); 
0086   w = spm_input('Widths in XYZ (mm)', '+1', 'e', [], 3);
0087   d = sprintf('[%0.1f %0.1f %0.1f] box at [%0.1f %0.1f %0.1f]',w,c);
0088   l = sprintf('box_w-%0.0f_%0.0f_%0.0f-%0.0f_%0.0f_%0.0f',w,c);
0089   o = maroi_box(struct('centre',c,'widths',w));
0090  case 'box_lims'
0091   X = sort(spm_input('Range in X (mm)', '+1', 'e', [], 2)); 
0092   Y = sort(spm_input('Range in Y (mm)', '+1', 'e', [], 2)); 
0093   Z = sort(spm_input('Range in Z (mm)', '+1', 'e', [], 2));
0094   A = [X Y Z];
0095   c = mean(A);
0096   w = diff(A);
0097   d = sprintf('box at %0.1f>X<%0.1f %0.1f>Y<%0.1f %0.1f>Z<%0.1f',A);
0098   l = sprintf('box_x_%0.0f:%0.0f_y_%0.0f:%0.0f_z_%0.0f:%0.0f',A);
0099   o = maroi_box(struct('centre',c,'widths',w));
0100  case 'quit'
0101   o = [];
0102   return
0103  otherwise
0104   error(['Strange ROI type: ' roitype]);
0105 end
0106 o = descrip(o,d);
0107 o = label(o,l);

Generated on Thu 17-Mar-2016 01:14:46 by m2html © 2005