Home > marsbar > mars_blobs2rois.m

mars_blobs2rois

PURPOSE ^

creates ROIs from spm_results_ui SPM

SYNOPSIS ^

function mars_blobs2rois(xSPM, roipath, rootn)

DESCRIPTION ^

 creates ROIs from spm_results_ui SPM 
 FORMAT mars_blobs2rois(xSPM, roipath, rootn)
  
 Inputs
 xSPM         - SPM results structure with needed fields
                  title
                  XYZ   - voxel coordinates of activated points
                  Z     - statistic values for activated points
                  M     - 4x4 matrix from voxels to mm 
 roipath      - directory in which to write ROIs
 rootn        - root name for ROI(s) 

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mars_blobs2rois(xSPM, roipath, rootn)
0002 % creates ROIs from spm_results_ui SPM
0003 % FORMAT mars_blobs2rois(xSPM, roipath, rootn)
0004 %
0005 % Inputs
0006 % xSPM         - SPM results structure with needed fields
0007 %                  title
0008 %                  XYZ   - voxel coordinates of activated points
0009 %                  Z     - statistic values for activated points
0010 %                  M     - 4x4 matrix from voxels to mm
0011 % roipath      - directory in which to write ROIs
0012 % rootn        - root name for ROI(s)
0013 %
0014 % $Id$
0015 
0016 if nargin < 1
0017   error('Need SPM structure');
0018 end
0019 if nargin < 2
0020   pt = [];
0021 end
0022 if nargin < 3
0023   roipath = '';
0024 end
0025 if nargin < 4
0026   rootn = '';
0027 end
0028 
0029 if isempty(roipath)
0030   roipath = spm_get([-1 0], '', 'Directory to save ROI(s)');
0031 end
0032 if isempty(roipath)
0033   return
0034 end
0035 if isempty(rootn)
0036   rootn = mars_utils('str2fname', xSPM.title);
0037   rootn = spm_input('Root name for clusters', '+1', 's', rootn);
0038 end
0039 
0040 pre_ones = ones(1, size(xSPM.XYZ,2));
0041 clusters = spm_clusters(xSPM.XYZ);
0042 [N Z maxes A] = spm_max(xSPM.Z,xSPM.XYZ);
0043 
0044 for c = unique(A(:)')
0045   % maximum maximum for this cluster
0046   tmp = Z; tmp(A~=c) = -Inf; 
0047   [tmp mi] = max(tmp);
0048   % voxel coordinate of max
0049   vco = maxes(:, mi);
0050   % in mm
0051   maxmm = xSPM.M * [vco; 1];
0052   maxmm = maxmm(1:3);
0053   % corresponding cluster in spm_clusters, XYZ for cluster
0054   my_c = clusters(all(xSPM.XYZ == vco * pre_ones));
0055   XYZ = xSPM.XYZ(:, clusters == my_c(1));
0056   if ~isempty(XYZ)
0057     % file name and labels
0058     d = sprintf('%s cluster at [%0.1f %0.1f %0.1f]', rootn, maxmm);
0059     l = sprintf('%s_%0.0f_%0.0f_%0.0f', rootn, maxmm);
0060     fn = mars_utils('str2fname', l);
0061     fname = maroi('filename', fullfile(roipath, fn));
0062     o = maroi_pointlist(struct('XYZ',XYZ,'mat',xSPM.M,...
0063                    'descrip',d, 'label', l), ...
0064             'vox');
0065     fprintf('\nSaving %s as %s...', d, fname);
0066     saveroi(o, fname);
0067   end
0068 end
0069 fprintf('\nDone...\n');

Generated on Sat 19-Nov-2011 16:12:40 by m2html © 2005