Primary slice direction and volume CRS orientation
To get the primary slice direction:
To get the orientation string for the 3 axes:
The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
In this document, we show how to derive various data from the header of FreeSurfer brain volume files.
The header of MGH (or MGZ) brain volume files can contain important information on the volume data, including orientation, slice thickness, and MR acquisition parameters. The freesurferformats package provides functions to compute important properties from the header.
When reading a brain volume, make sure you explicitely request the full data, including the header:
library("freesurferformats");
mgh_file = system.file("extdata", "brain.mgz", package = "freesurferformats", mustWork = TRUE);
brain = read.fs.mgh(mgh_file, with_header = TRUE);
This will give you an fs.volume
instance, which is very
handy. To see the header information, just type the variable name to
print it:
brain
Brain volume with 4 dimensions '256x256x256x1' and 16777216 voxels.
- Data dimensions according to header: '256x256x256x1'.
- Datatype according to header is 0 ('MRI_UCHAR'), values are in range [0.00, 156.00].
- Header contains vox2ras transformation information. Voxel size is 1.00 x 1.00 x 1.00 mm.
- Volume is conformed, pimary slice direction is 'coronal', orientation is 'LIA'.
- Header contains MR acquisition parameters: TR: 2300.00 msec, TE: 2.01 msec, TI: 900.00 msec, flip angle: 9.00 degrees, fov = 256.000.
You can access the volume data in brain$data
and the
header in brain$header
now.
Not all MGH files contain a valid header that can be used to compute
more information. To check your data, use the
mghheader.is.ras.valid
function:
If the header is valid, it can be used to compute various
transformation matrices. Here is an example that computes the
vox2ras
matrix and then uses it to get the right,
anterior, superior (RAS) coordinates of the voxel at column,
row, slice (CRS) index (128, 128, 128)
:
voxel = c(128, 128, 128);
vox2ras = mghheader.vox2ras(brain);
ras_coords = vox2ras %*% c(voxel, 1); # the 1 is because we use homogeneous coordinates
You can use the following functions in the same way to compute various matrices:
mghheader.vox2ras
– CRS voxel index to RAS coordinate
matrix (compute the position of a voxel).mghheader.ras2vox
– RAS coordinate to CRS voxel index
matrix (compute the voxel at a position).mghheader.vox2ras.tkr
– like vox2ras above, but uses
tkregister space.mghheader.ras2vox.tkr
– like ras2vox above, but uses
tkregister space.mghheader.tkreg2scanner
– RAS to RAS transform between
tkregister space and scanner space.mghheader.scanner2tkreg
– RAS to RAS transform between
scanner space and tkregister space.To get the primary slice direction:
To get the orientation string for the 3 axes:
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.