0001 function mars_blobs2rois(xSPM, roipath, rootn)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0041 tmp = Z; tmp(A~=c) = -Inf;
0042 [tmp mi] = max(tmp);
0043
0044 vco = maxes(:, mi);
0045
0046 maxmm = xSPM.M * [vco; 1];
0047 maxmm = maxmm(1:3);
0048
0049 my_c = clusters(all(xSPM.XYZ == vco * pre_ones));
0050 XYZ = xSPM.XYZ(:, clusters == my_c(1));
0051 if ~isempty(XYZ)
0052
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');