Attachment 'spm_VOI_Custom.m'
Download 1 function TabDat = spm_VOI_Custom(SPM,xSPM,hReg,CustomParams)
2 % Custom variant of SPM5's function to allow greater customisation.
3 % All custom parameters are optional, and are defined in the CustomParams
4 % Struct:
5 % Num = 16 - maxima per cluster
6 % Dis = 4 - distance among maxima (mm)
7 % xyzmm - mm coordinates (GUI input if undefined) NB column vector!
8 % SPACE = S- shape of VOI (S for sphere, B for box, I for image)
9 % D - mm radius for sphere, xyz dimensions for box, path for image.
10 % (GUI input if undefined)
11 % To use, first bring up some results in SPM to obtain the necessary
12 % SPM, xSPM and hReg inputs.
13 % 5/1/2010 J Carlin
14
15 % List of local maxima and adjusted p-values for a small Volume of Interest
16 % FORMAT TabDat = spm_VOI(SPM,xSPM,hReg,[CustomParams])
17 %
18 % SPM - structure containing analysis details (see spm_spm)
19 %
20 % xSPM - structure containing SPM, distribution & filtering details
21 % - required fields are:
22 % .swd - SPM working directory - directory containing current SPM.mat
23 % .Z - minimum of n Statistics {filtered on u and k}
24 % .n - number of conjoint tests
25 % .STAT - distribution {Z, T, X or F}
26 % .df - degrees of freedom [df{interest}, df{residual}]
27 % .u - height threshold
28 % .k - extent threshold {resels}
29 % .XYZ - location of voxels {voxel coords}
30 % .XYZmm - location of voxels {mm}
31 % .S - search Volume {voxels}
32 % .R - search Volume {resels}
33 % .FWHM - smoothness {voxels}
34 % .M - voxels - > mm matrix
35 % .VOX - voxel dimensions {mm}
36 % .DIM - image dimensions {voxels} - column vector
37 % .Vspm - Mapped statistic image(s)
38 % .Ps - P vlues in searched voxels (for FDR)
39 %
40 % hReg - Handle of results section XYZ registry (see spm_results_ui.m)
41 %
42 % TabDat - Structure containing table data
43 % - see spm_list for definition
44 %
45 %_______________________________________________________________________
46 %
47 % spm_VOI is called by the SPM results section and takes variables in
48 % SPM to compute p-values corrected for a specified volume of interest.
49 %
50 % The volume of interest may be defined as a box or sphere centred on
51 % the current voxel or by a mask image.
52 %
53 % If the VOI is defined by a mask this mask must have been defined
54 % independently of the SPM (e.g.using a mask based on an orthogonal
55 % contrast)
56 %
57 % External mask images should be in the same orientation as the SPM
58 % (i.e. as the input used in stats estimation). The VOI is defined by
59 % voxels with values greater than 0.
60 %
61 % FDR computations are similarly resticted by the small search volume
62 %
63 % See also: spm_list
64 %_______________________________________________________________________
65 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
66
67 % Karl Friston
68 % $Id: spm_VOI.m 1770 2008-06-01 01:01:12Z Darren $
69
70
71 %-Parse arguments
72 %-----------------------------------------------------------------------
73 if nargin < 2, error('insufficient arguments'), end
74 if nargin < 3, hReg = []; end
75 if nargin < 4, CustomParams = struct; end
76
77 if ~isfield(CustomParams,'Num'), CustomParams.Num = 16; end
78 if ~isfield(CustomParams,'Dis'), CustomParams.Dis = 4; end
79
80 %Num = 16; % maxima per cluster
81 %Dis = 04; % distance among maxima (mm)
82
83 %-Title
84 %-----------------------------------------------------------------------
85 spm('FigName',['SPM{',xSPM.STAT,'}: Small Volume Correction']);
86
87 %-Get current location {mm}
88 %-----------------------------------------------------------------------
89 %xyzmm = spm_results_ui('GetCoords');
90 if ~isfield(CustomParams,'xyzmm')
91 CustomParams.xyzmm = spm_results_ui('GetCoords');
92 else
93 CustomParams.xyzmm = reshape(CustomParams.xyzmm,3,1); % Ensure row vector
94 end
95
96 %-Specify search volume
97 %-----------------------------------------------------------------------
98 str = sprintf(' at [%.0f,%.0f,%.0f]',CustomParams.xyzmm(1),CustomParams.xyzmm(2),CustomParams.xyzmm(3));
99
100 if ~isfield(CustomParams,'SPACE')
101 CustomParams.SPACE = spm_input('Search volume...',-1,'m',...
102 {['Sphere',str],['Box',str],'Image'},['S','B','I']);
103 end
104
105 % voxels in entire search volume {mm}
106 %-----------------------------------------------------------------------
107 XYZmm = SPM.xVol.M(1:3,:)*[SPM.xVol.XYZ; ones(1, SPM.xVol.S)];
108 Q = ones(1,size(xSPM.XYZmm,2));
109 O = ones(1,size( XYZmm,2));
110 FWHM = xSPM.FWHM;
111
112
113 switch CustomParams.SPACE
114
115 case 'S' %-Sphere
116 %---------------------------------------------------------------
117 if ~isfield(CustomParams,'D')
118 CustomParams.D = spm_input('radius of VOI {mm}',-2);
119 end
120
121 str = sprintf('%0.1fmm sphere',CustomParams.D);
122 j = find(sum((xSPM.XYZmm - CustomParams.xyzmm*Q).^2) <= CustomParams.D^2);
123 k = find(sum(( XYZmm - CustomParams.xyzmm*O).^2) <= CustomParams.D^2);
124 CustomParams.D = CustomParams.D./xSPM.VOX;
125
126
127 case 'B' %-Box
128 %---------------------------------------------------------------
129 if ~isfield(CustomParams,'D')
130 CustomParams.D = spm_input('box dimensions [k l m] {mm}',-2);
131 end
132
133 if length(CustomParams.D)~=3, CustomParams.D = ones(1,3)*CustomParams.D(1); end
134 str = sprintf('%0.1f x %0.1f x %0.1f mm box',CustomParams.D(1),CustomParams.D(2),CustomParams.D(3));
135 j = find(all(abs(xSPM.XYZmm - CustomParams.xyzmm*Q) <= CustomParams.D(:)*Q/2));
136 k = find(all(abs( XYZmm - CustomParams.xyzmm*O) <= CustomParams.D(:)*O/2));
137 CustomParams.D = CustomParams.D./xSPM.VOX;
138
139
140 case 'I' %-Mask Image
141 %---------------------------------------------------------------
142 if ~isfield(CustomParams,'D')
143 Msk = spm_select(1,'image','Image defining search volume');
144 end
145
146 CustomParams.D = spm_vol(Msk);
147 str = sprintf('image mask: %s',spm_str_manip(Msk,'a30'));
148
149 % fix up string so tex interpreter works correctly
150 str = strrep(str,'\','\\');
151 str = strrep(str,'_','\_');
152 str = strrep(str,'^','\^');
153 str = strrep(str,'{','\{');
154 str = strrep(str,'}','\}');
155
156 VOX = sqrt(sum(CustomParams.D.mat(1:3,1:3).^2));
157 FWHM = FWHM.*(xSPM.VOX./VOX);
158 XYZ = CustomParams.D.mat \ [xSPM.XYZmm; ones(1, size(xSPM.XYZmm, 2))];
159 j = find(spm_sample_vol(CustomParams.D, XYZ(1,:), XYZ(2,:), XYZ(3,:),0) > 0);
160 XYZ = CustomParams.D.mat \ [ XYZmm; ones(1, size( XYZmm, 2))];
161 k = find(spm_sample_vol(CustomParams.D, XYZ(1,:), XYZ(2,:), XYZ(3,:),0) > 0);
162
163 end
164
165 xSPM.S = length(k);
166 xSPM.R = spm_resels(FWHM,CustomParams.D,CustomParams.SPACE);
167 xSPM.Z = xSPM.Z(j);
168 xSPM.XYZ = xSPM.XYZ(:,j);
169 xSPM.XYZmm = xSPM.XYZmm(:,j);
170 xSPM.Ps = xSPM.Ps(k);
171
172 %-Tabulate p values
173 %-----------------------------------------------------------------------
174 str = sprintf('search volume: %s',str);
175 if any(strcmp(CustomParams.SPACE,{'S','B'}))
176 str = sprintf('%s at [%.0f,%.0f,%.0f]',str,CustomParams.xyzmm(1),CustomParams.xyzmm(2),CustomParams.xyzmm(3));
177 end
178
179 TabDat = spm_list('List',xSPM,hReg,CustomParams.Num,CustomParams.Dis,str);
180
181 %-Reset title
182 %-----------------------------------------------------------------------
183 spm('FigName',['SPM{',xSPM.STAT,'}: Results']);
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.