- 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?