FreeSurfer coordinate spaces and translation #1249
effigies
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Following are some notes on handling "volume geometry" in FreeSurfer, and calculating the tkregister affine, the scanner affine, and the transform between the two.
This was motivated by a desire to understand what
mris_convert --to-scanner
is actually doing. Various pieces of this exist in nibabel, nitransforms, HCP pipelines and sMRIPrep, but there isn't really one place that puts it all together. Probably the closest is https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems, but this brings the underlying data structure to the fore and hopefully this will be a useful reference for those more comfortable reading Python.Volume geometry
FreeSurfer encodes the affine as zooms, direction cosines, and
c_ras
, which is the the RAS coordinate of the center of the data array. We will model this with a simple dataclass:This volume geometry gets represented in an MGHHeader as follows:
In a GIFTI surface file, it appears as follows:
Equivalent structures also appear in the footer of surface files:
The LTA affine transform file format also contains a representation of the volume geometry, but I won't go into that here.
Here are functions to create
VolGeom
s from each structure:Affines
We can define the tkregister and scanner affines as follows:
Note that these would be the same if
c_ras == [0, 0, 0]
andself.cosines == tkrcosines
. When the image is non-oblique, the difference is the offset of the image center from the origin (in mm), orc_ras
. Some tools (HCP pipelines, older versions of fMRIPrep) have mistakenly addedc_ras
to TKR coordinates, which works for non-oblique datasets.To find the transform from RAS coordinates in tkregister space to RAS coordinates in scanner space, we can multiply the scanner affine by the inverse of the tkregister affine:
Full definition
Converting a FreeSurfer GIFTI surface to RAS coordinates
Convert
lh.white
to GIFTI with and without--to-scanner
:Now we can perform our own
--to-scanner
conversion:And compare to FreeSurfer's:
Beta Was this translation helpful? Give feedback.
All reactions