External Email - Use Caution
Dear FreeSurfer devs,
I'm writing a program in JavaScript that converts FreeSurfer surface (mesh) files to other formats, which require the vertices to sit in scanner RAS coordinates.
Right now I'm relying on the FreeSurfer *brain.finalsurf.mgz* or *T1.mgz* file to obtain the Torig (vox to tkr-ras) and Norig (vox to scanner ras) matrices, and using these matrices to calculate the rigid transform. This approach requires the users to upload the mgz volume files (but I only need the transforms).
Today I found that each binary surface file (e.g. lh.pial) has a little footer that starts with uint32 sequence `2 0 20`, followed by the meta information such as xras, yras, zras, and cras. For example:
valid = 1 # volume info valid filename = ../mri/filled-pretess127.mgz volume = 256 256 256 voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00 xras = -1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 yras = 0.000000000000000e+00 0.000000000000000e+00 -1.000000000000000e+00 zras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00 cras = -1.000000000000000e+00 -1.700000000000000e+01 1.900000000000000e+01 \u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0001
From what I understand, cras is the xyz of the volume center, which is the translation from mesh vertices xyz (in tkr-ras) to native scanner RAS.
I wonder if I can rely on this information to calculate the transform from tkr-ras to scan-ras, if so, where are the rotation matrices? (Affine/rigid transform is a 4x4 matrix, if cras is the translation, where are the first 3x3 elements, are those always identity matrices?)
Best, - Dipterix
These three TAGs (TAG_SURF_DATASPACE, TAG_SURF_MATRIXDATA, TAG_SURF_TRANSFORMEDSPACE) are available in the surface files if they are output from Freesurfer dev version.
They are the same as the metadata DataSpace/MatrixData/TransformedSpace in GIFTI. You can use the information to convert [x, y, z] coordinates between TAG_SURF_DATASPACE and TAG_SURF_TRANSFORMEDSPACE.
See freesurfer/utils/mrisurf_io.cpp:: __MRISwriteTriangularSurfaceTags() for implementation details.
Best,
Yujing
From: freesurfer-bounces@nmr.mgh.harvard.edu freesurfer-bounces@nmr.mgh.harvard.edu On Behalf Of Dipterix Wang Sent: Thursday, April 11, 2024 10:50 AM To: Freesurfer support list freesurfer@nmr.mgh.harvard.edu Subject: [Freesurfer] Surface vertex tkr-ras to native T1 RAS without volume files
External Email - Use Caution Dear FreeSurfer devs,
I'm writing a program in JavaScript that converts FreeSurfer surface (mesh) files to other formats, which require the vertices to sit in scanner RAS coordinates.
Right now I'm relying on the FreeSurfer brain.finalsurf.mgz or T1.mgz file to obtain the Torig (vox to tkr-ras) and Norig (vox to scanner ras) matrices, and using these matrices to calculate the rigid transform. This approach requires the users to upload the mgz volume files (but I only need the transforms).
Today I found that each binary surface file (e.g. lh.pial) has a little footer that starts with uint32 sequence `2 0 20`, followed by the meta information such as xras, yras, zras, and cras. For example:
valid = 1 # volume info valid filename = ../mri/filled-pretess127.mgz volume = 256 256 256 voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00 xras = -1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 yras = 0.000000000000000e+00 0.000000000000000e+00 -1.000000000000000e+00 zras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00 cras = -1.000000000000000e+00 -1.700000000000000e+01 1.900000000000000e+01 \u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0001
From what I understand, cras is the xyz of the volume center, which is the translation from mesh vertices xyz (in tkr-ras) to native scanner RAS.
I wonder if I can rely on this information to calculate the transform from tkr-ras to scan-ras, if so, where are the rotation matrices? (Affine/rigid transform is a 4x4 matrix, if cras is the translation, where are the first 3x3 elements, are those always identity matrices?)
Best, - Dipterix
freesurfer@nmr.mgh.harvard.edu