Errors moving between head space and MNI

  • MNE version: 1.7.1
  • operating system: Ubuntu 18.04.6 LTS

Dear users,
I’m working with some MEG data that has been co-registered to an anatomical image using mne.coreg(), meaning I have a head → MR transform matrix named MRtrans. I also have a Freesurfer directory for this subject.

I’d like to get a location in head space based on MNI coordinates. I can easily get MNI coords based on head position, using mne.head_to_mni():

# Define some coords in head space
head_coords = np.array([-0.02241, -0.02314, 0.06732])

# Transform to mni space
mni_coords = mne.head_to_mni(head_coords, subject=MRsubject, mri_head_t=MRItrans, subjects_dir=subjectsDir, verbose=None)

# Print result
print(mni_coords)

This returns

[[-21.85401067 -30.08148144 22.98934765]]

However, I’m struggling to get coords in the other direction (MNI → head). I attempted this using the talairach.xfm transformation from the Freesurfer directory, which I believe is for MRI → MNI transform (according to this documentation).

# Read the  talairach.xfm transform
head_to_mni = mne.read_talxfm(MRsubject, subjectsDir)

# Extract the matrix
head_to_mni_matrix = head_to_mni['trans'] 

# Invert the matrix to go from MNI to head space
mni_to_head_matrix = np.linalg.inv(head_to_mni_matrix)

# Convert mni_coords back to head space
new_head_coords = mne.transforms.apply_trans(mni_to_head_matrix, mni_coords)

# Print result
print(new_head_coords/1000) # convert from mm to meters

Returns something different from my original head_coords ([-0.02241, -0.02314, 0.06732]):

[[-0.01706248 -0.02348607 0.01794889]]

What am I doing wrong here?

Two things:

  1. mne.read_talxfm does not return the head_to_mni transform but the mri_to_mni transform.
  2. mne.head_to_mni also multiplies the result by 1000 because MNI coordinates are usually reported in millimeters instead of meters.

So, to fix your code:

import mne

head_to_mri = MRItrans
mri_to_mni = mne.read_talxfm(subject=MRsubject, subjects_dir=subjectsDir)
head_to_mni = mne.transforms.combine_transforms(head_to_mri, mri_to_mni, "head", "mni_tal")
mni_to_head = mne.transforms.invert_transform(head_to_mni)

head_coords = np.array([-0.02241, -0.02314, 0.06732])
mni_coords = mne.head_to_mni(head_coords, subject=MRsubject, mri_head_t=head_to_mri, subjects_dir=subjectsDir)

print("head      (m) ", head_coords)
print("head->mni (mm)", mni_coords)
print("mni->head (m) ", mne.transforms.apply_trans(mni_to_head, mni_coords / 1000))
2 Likes

Worked like a dream. Thanks!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.