999
Comment:
|
← Revision 3 as of 2013-03-07 21:24:25 ⇥
1199
converted to 1.6 markup
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
SPM likes its coordinates in mm. If you ever find the need to use voxel coordinates, e.g. for running analyses in other software packages, the below function gives a quick transform. Once added to your Matlab path, you can find your ROI in the SPM results interface, and then type mm_to_vox (or whatever you've saved the function as) to get your current position in voxels. | SPM likes its coordinates in mm. If you ever find the need to use voxel coordinates, e.g. for running analyses in other software packages, the below function gives a quick transform. Once added to your Matlab path, you can find your ROI in the SPM results interface, and then type mm_to_vox(hReg,xSPM) to get your current position in voxels. The relevant inputs (hReg, xSPM) must be in your workspace, but don't worry as this will always be the case if you used the standard SPM results viewer to bring up your data. (updated 10 June to fix incompatibility with SPM8) |
Line 7: | Line 9: |
% SPM results viewer. Uses naughty functions like assignin and evalin, % so caveat emptor... % J Carlin 19/3/2009 |
% SPM results viewer. % J Carlin 10/6/2011 |
Line 11: | Line 12: |
function xyz_vox = mm_to_vox | %function xyz_vox = mm_to_vox(hReg,xSPM) function xyz_vox = mm_to_vox(hReg,xSPM) |
Line 13: | Line 15: |
hReg = findobj('Tag','hReg'); % get results figure handle | %hReg = findobj('Tag','hReg'); % get results figure handle |
Line 15: | Line 17: |
xyz_vox = evalin('base','xSPM.iM*[xyz_mm;1]'); % avoid passing xSPM explicitly | xyz_vox = xSPM.iM*[xyz_mm;1]; %evalin('base','xSPM.iM*[xyz_mm;1]'); % avoid passing xSPM explicitly |
Getting from SPM world coordinates (mm) to voxel coordinates
SPM likes its coordinates in mm. If you ever find the need to use voxel coordinates, e.g. for running analyses in other software packages, the below function gives a quick transform. Once added to your Matlab path, you can find your ROI in the SPM results interface, and then type mm_to_vox(hReg,xSPM) to get your current position in voxels. The relevant inputs (hReg, xSPM) must be in your workspace, but don't worry as this will always be the case if you used the standard SPM results viewer to bring up your data.
(updated 10 June to fix incompatibility with SPM8)
% Returns the voxel coordinates for the current position in the % SPM results viewer. % J Carlin 10/6/2011 %function xyz_vox = mm_to_vox(hReg,xSPM) function xyz_vox = mm_to_vox(hReg,xSPM) %hReg = findobj('Tag','hReg'); % get results figure handle xyz_mm = spm_XYZreg('GetCoords',hReg); % get mm coordinates for current locationassignin('base','xyz_mm',xyz_mm); % puts xyz_mm in base workspace xyz_vox = xSPM.iM*[xyz_mm;1]; %evalin('base','xSPM.iM*[xyz_mm;1]'); % avoid passing xSPM explicitly xyz_vox = xyz_vox(1:3);