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)

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 if nargin < 1
0015   error('Need SPM structure');
0016 end
0017 if nargin < 2
0018   roipath = '';
0019 end
0020 if nargin < 3
0021   rootn = '';
0022 end
0023 
0024 if isempty(roipath)
0025   roipath = spm_get([-1 0], '', 'Directory to save ROI(s)');
0026 end
0027 if isempty(roipath)
0028   return
0029 end
0030 if isempty(rootn)
0031   rootn = mars_utils('str2fname', xSPM.title);
0032   rootn = spm_input('Root name for clusters', '+1', 's', rootn);
0033 end
0034 
0035 pre_ones = ones(1, size(xSPM.XYZ,2));
0036 clusters = spm_clusters(xSPM.XYZ);
0037 [N Z maxes A] = spm_max(xSPM.Z,xSPM.XYZ);
0038 
0039 for c = unique(A(:)')
0040   % maximum maximum for this cluster
0041   tmp = Z; tmp(A~=c) = -Inf; 
0042   [tmp mi] = max(tmp);
0043   % voxel coordinate of max
0044   vco = maxes(:, mi);
0045   % in mm
0046   maxmm = xSPM.M * [vco; 1];
0047   maxmm = maxmm(1:3);
0048   % corresponding cluster in spm_clusters, XYZ for cluster
0049   my_c = clusters(all(xSPM.XYZ == vco * pre_ones));
0050   XYZ = xSPM.XYZ(:, clusters == my_c(1));
0051   if ~isempty(XYZ)
0052     % file name and labels
0053     d = sprintf('%s cluster at [%0.1f %0.1f %0.1f]', rootn, maxmm);
0054     l = sprintf('%s_%0.0f_%0.0f_%0.0f', rootn, maxmm);
0055     fn = mars_utils('str2fname', l);
0056     fname = maroi('filename', fullfile(roipath, fn));
0057     o = maroi_pointlist(struct('XYZ',XYZ,'mat',xSPM.M,...
0058         'descrip',d, 'label', l), ...
0059         'vox');
0060     fprintf('\nSaving %s as %s...', d, fname);
0061     saveroi(o, fname);
0062   end
0063 end
0064 fprintf('\nDone...\n');

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