Print

Print


Dear Lisa,

to convert MNI coordinates to subject space in SPM12 for TMS neuronavigation, I always use a snippet of code posted by John Ashburner on this list a while ago. I can't find his post right now, so I'll just send you my version of his code.

----------------
function xyz_native = calculate_subj_coord_SPM12(Pnative,Py,xyz_mni)
% This function transforms coordinates in MNI-space into individual subject
% space using the forward deformations file 'y_*.nii' created by SPM12's
% normalization procedure. 
%
% Requires SPM12
%
% Arguments: 
% - Pnative = path to original T1 scan of subject in .nii-format
% - Py = path to y_*.nii file (forward deformations)
% - xyz_mni = coordinates in MNI-space that should be transformed
%
% Example usage:
% xyz_native = calculate_subj_coord_SPM12('/data/s225274c-0003-00001-000176-01.nii', ...
% '/data/y_s225274c-0003-00001-000176-01.nii', [-37 -21 58])

% voxel coordinate in MNI space of y_*.nii
Nii = nifti(Py);
iM  = inv(Nii.mat);
ijk = iM(1:3,:)*[xyz_mni 1]';

% mm coordinate in native images
native_x = spm_bsplins(Nii.dat(:,:,:,1,1),ijk(1),ijk(2),ijk(3),[1 1 1 0 0 0]);
native_y = spm_bsplins(Nii.dat(:,:,:,1,2),ijk(1),ijk(2),ijk(3),[1 1 1 0 0 0]);
native_z = spm_bsplins(Nii.dat(:,:,:,1,3),ijk(1),ijk(2),ijk(3),[1 1 1 0 0 0]);
xyz_native = [native_x native_y native_z];

% voxel coordinate in native image Pnative
Nii_image  = nifti(Pnative);
iM2        = inv(Nii_image.mat);
ijk_native = iM2(1:3,:)*[native_x native_y native_z 1]';
----------------

I hope this answers your question!

All the best,
Phil

----------------------
Philipp Kuhnke, M.Sc.
Ph.D. Student
Max Planck Institute for Human Cognitive and Brain Sciences,
Leipzig, Germany