Transforming_SPM_world_coordinates_to_voxel_coordinates - MRC CBU Imaging Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
In thi sntence, what word is mad fro the mising letters?

location: Transforming_SPM_world_coordinates_to_voxel_coordinates

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);