I had some issues with the skull stripping in Freesurfer and in some cases
I obtained a better one using the fieldtrip/spm pipeline. Now that I obtain
the inner_skull.surf I guess I have to convert it to the freesurfer
coordinates otherwise it's not aligned with the mri for example (see image
attached). How can I do the transformation ? I tried but unsuccessfully.
you can use plot_bem in mne-python to check things and you can write a
surface file in .surf format.
Keep in mind you need to know what coordinate frame the surface that is
created by fieldtrip/spm lives in. If it's MRI voxels (?), then you'd want
a MRI voxel (just called "vox" in MNE) to FreeSurfer Surface RAS MRI (just
called "mri" in MNE) transformation. In nibabel this would be something
like:
rr, tris = mne.read_surface('inner_skull.surf') # in mm
mri = nibabel.load('SUBJECTS_DIR/SUBJECT/mri/T1.mgz')
xform = mri.header.get_vox2ras_tkr() # in mm
rr = mne.transforms.apply_trans(rr, xform)
mne.write_surface('inner_skull_fixed.surf', rr, tris)
This might or might not work depending on the coordinate frame that
fieldtrip/spm actually uses. For example, if the volume is in just
MRI/Scanner RAS coordinates (probably more likely?), you'll need to take
the points and convert them from MRI/scanner RAS to FreeSurfer surface RAS,
which would involve something like:
a = mri.header.affine # vox->ras
b = mri.header.get_vox2ras_tkr() # vox->mri
xform = b @ np.linalg.inv(a) # ras->mri
and apply this xform instead and save as above. For more information, see: