Skip to content

ANTS transforms on volume (MNC, NIFTI) and surface (OBJ) files

NadiaBlostein edited this page Apr 20, 2021 · 26 revisions

RAS file orientation: Display MRI.{mnc,nii.gz}

  • x-axis: values increase from left (L) to right (R)
  • y-axis: values increase from posterior (P) to anterior (A)
  • z-axis: values increase from inferior (I) to superior (S)

Figure: MRI from Neudorfer, C., Germann, J., Elias, G. J. B., Gramer, R., Boutet, A., & Lozano, A. M. (2020). A high-resolution in vivo magnetic resonance imaging atlas of the human hypothalamic region. Scientific Data, 7(1), 305.

RAS file orientation: register MRI.{mnc,nii.gz}

Figure: MRI from Neudorfer, C., Germann, J., Elias, G. J. B., Gramer, R., Boutet, A., & Lozano, A. M. (2020). A high-resolution in vivo magnetic resonance imaging atlas of the human hypothalamic region. Scientific Data, 7(1), 305.

Transform Files: MAT, XFM and MNC

  • .mat and .xfm files store information in the form of matrices and therefore only contain information on linear transformations
  • .mnc or .nii.gz transform files store information in the form of vector fields, and therefore can encode either linear or nonlinear transformations

Extracting the vector field from a .mat file (ie going from .mat to .mnc):

$ antsApplyTransforms -d 3 -t transform.xfm -r reference_MRI.mnc -o [transform.mnc,1] --verbose 
	# -i : this does not take an input
	# -r: template space where voxels are defined (how big they are and how they are oriented in space) 
	# -o [ output.mnc,1 ]: outputs a composite warp field (combination of several warp fields)

Transform files (XFM, MNC or NIIGZ) on volumes (MNC, NIIGZ) or surface (OBJ)

MNC volume files:

  • positive scaling (XFM or MNC transform) shrinks the volume
  • translations (XFM or MNC transform) applied along +L +P +S

NIIGZ volume files:

  • positive scaling (XFM or NIIGZ transform) shrinks the volume (same as for MNC files)
  • translations (XFM or NIIGZ transform) applied along +R +A +I (inverse of LPS)

OBJ surface files

  • positive scaling (XFM, MNC or NIIGZ transform) increases the surface (whether you apply the transform via ants_transform_objects.sh OR ants_transform_objects_RAS_LPS_convert.sh)
  • translations (XFM, MNC or NIIGZ transform) applied along +L +P +S with ants_transform_objects_RAS_LPS_convert.sh and +R +A +S with ants_transform_objects.sh

See below for visual proof.

Create sphere volume and surface files

The sphere volume (MNC format) and surface files (OBJ) will be used for downstream testing. Note that .mnc is needed to define the voxels (size and direction) of the spherical volume.

Create surface file

  1. create a sphere in Meshlab, save as .stl
  2. convert .stl to .obj:
python vtk_meshconvert.py -i sphere.stl -a -o sphere.obj

Create volume files (the following functions are MNC-specific)

scan_object_to_volume <referenceMRI>.mnc sphere.obj sphere_volume.mnc
ImageMath 3 sphere_volume.mnc FillHoles sphere_volume.mnc 2
ExtractRegionFromImage 3 sphere_volume.mnc sphere_volume.mnc 1
ImageMath 3 sphere_volume.mnc PadImage sphere_volume.mnc 10

# convert fo NIFTI
mnc2nii sphere_volume.mnc 
gzip sphere_volume.nii 
vol_surf

Figure: sphere surface (green) and volume (white) (Display sphere_volume.mnc sphere.obj)

Transform Files on MNC Volume

Scale along the x-axis

param2xfm -scale 2 1 1 scale.xfm
antsApplyTransforms -d 3 -t scale.xfm -r sphere_volume.mnc -o [scale.mnc,1] --verbose 

# XFM Transform on MNC Volume:
antsApplyTransforms -d 3 -i sphere_volume.mnc -r sphere_volume.mnc -t scale.xfm -o sphere_volume_scaleXFM.mnc

# MNC Transform on MNC Volume:
antsApplyTransforms -d 3 -i sphere_volume.mnc -r sphere_volume.mnc -t scale.mnc -o sphere_volume_scaleMNC.mnc

Both the XFM transform and MNC transform perform the inverse operation on the MNC file: they shrink the sphere by a factor of 2, along the x-axis. You obtain the same results if you scale along the y-axis (-scale 1 2 1 …) or along the z-axis (-scale 1 1 2…).

scale_x_MNC

Figure: scale along the x-axis (register sphere_volume.mnc sphere_volume_scaleXFM.mnc sphere_volume_scaleMNC.mnc)

Translations along the x-, y- and z- axes

param2xfm -translation 2 0 0 translation.xfm # along the x axis
antsApplyTransforms -d 3 -t translation.xfm -r sphere_volume.mnc -o [translation.mnc,1] --verbose 

# XFM Transform on MNC Volume:
antsApplyTransforms -d 3 -i sphere_volume.mnc -r sphere_volume.mnc -t translation.xfm -o sphere_volume_translationXFM.mnc

# MNC Transform on MNC Volume:
antsApplyTransforms -d 3 -i sphere_volume.mnc -r sphere_volume.mnc -t translation.mnc -o sphere_volume_translationMNC.mnc

Just as is the case with scaling, translations perform the inverse operation on MNC files. Translations in the +x direction move the sphere to the left; translations in the +y direction move the sphere to the posterior direction; translations along the +z move the sphere to the inferior direction.

translation_x_MNC

Figure: left translation along the x-axis (register sphere_volume.mnc sphere_volume_translationXFM.mnc sphere_volume_translationMNC.mnc)

translation_y_MNC

Figure: posterior translation along the y-axis (same steps as above, but replace translation 2 1 1 with translation 1 2 1)

translation_z_MNC

Figure: inferior translation along the z-axis (same steps as above, but replace translation 2 1 1 with translation 1 1 2)

Transform Files on NII.GZ Volume

Scale along the x-axis

param2xfm -scale 2 1 1 scale.xfm
antsApplyTransforms -d 3 -t scale.xfm -r sphere_volume.nii.gz -o [scale.nii.gz,1] --verbose

# XFM Transform on NII.GZ Volume:
antsApplyTransforms -d 3 -i sphere_volume.nii.gz -r sphere_volume.nii.gz -t scale.xfm -o sphere_volume_scaleXFM.nii.gz

# NII.GZ Transform on NII.GZ Volume:
antsApplyTransforms -d 3 -i sphere_volume.nii.gz -r sphere_volume.nii.gz -t scale.nii.gz -o sphere_volume_scaleNIIGZ.nii.gz

Both the XFM transform and NII.GZ transform perform the inverse operation on the NII.GZ file: they shrink the sphere by a factor of 2, along the x-axis. You obtain the same results if you scale along the y-axis (-scale 1 2 1 …) or along the z-axis (-scale 1 1 2…).

scale_x_NIIGZ

Figure: scale along the x-axis (register sphere_volume.nii.gz sphere_volume_scaleXFM.nii.gz sphere_volume_scaleNIIGZ.nii.gz)

Translation along the x-, y- and z- axes

param2xfm -translation 2 0 0 translation.xfm # x-axis
antsApplyTransforms -d 3 -t translation.xfm -r sphere_volume.nii.gz -o [translation.nii.gz,1] --verbose

# XFM Transform on NII.GZ Volume:
antsApplyTransforms -d 3 -i sphere_volume.nii.gz -r sphere_volume.nii.gz -t translation.xfm -o sphere_volume_translationXFM.nii.gz

# NII.GZ Transform on NII.GZ Volume:
antsApplyTransforms -d 3 -i sphere_volume.nii.gz -r sphere_volume.nii.gz -t translation.nii.gz -o sphere_volume_translationNIIGZ.nii.gz

Unlike the case with scaling, translations perform the forward operation on NII.GZ files along the x- and y-axes. Translations in the +x direction move the sphere to the right; translations in the +y direction move the sphere to the anterior direction; translations along the +z move the sphere to the inferior direction.

translation_x_NIIGZ

Figure: right translation along the x-axis (register sphere_volume.nii.gz sphere_volume_translationXFM.nii.gz sphere_volume_translationNIIGZ.nii.gz)

translation_y_NIIGZ

Figure: anterior translation along the y-axis (same steps as above, but replace translation 2 1 1 with translation 1 2 1)

translation_z_NIIGZ

Figure: inferior translation along the z-axis (same steps as above, but replace translation 2 1 1 with translation 1 1 2)

Transform Files on OBJ surface

Scaling along the x-axis

param2xfm -scale 2 1 1 scale.xfm
antsApplyTransforms -d 3 -t scale.xfm -r sphere_volume.mnc -o [scale.mnc,1] --verbose 
antsApplyTransforms -d 3 -t scale.xfm -r sphere_volume.nii.gz -o [scale.nii.gz,1] --verbose

# XFM Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj scale.xfm sphere_scaleXFM.obj

# MNC Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj scale.mnc sphere_scaleMNC.obj

# NII.GZ Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj scale.nii.gz sphere_scaleNIIGZ.obj

# XFM Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj scale.xfm sphere_scaleXFM_RAS_LPS.obj

# MNC Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj scale.mnc sphere_scaleMNC_RAS_LPS.obj

# NII.GZ Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj scale.nii.gz sphere_scaleNIIGZ_RAS_LPS.obj

ALL of the above transforms perform the forward operation on the OBJ surface (ie the inverse of what they do to the MNC and NIFTI volumes): the sphere radius is doubled falong the x-axis. You obtain the same results if you scale along the y-axis (-scale 1 2 1 …) or along the z-axis (-scale 1 1 2…).

scale_x_obj

Figure: Original sphere (green) and transformed sphere (orange, doubled along the x-axis for any one of the 6 transforms above) (Display sphere.obj sphere_scale*obj)

Translating along the x-axis

param2xfm -translation 2 0 0 translation.xfm
antsApplyTransforms -d 3 -t translation.xfm -r sphere_volume.mnc -o [translation.mnc,1] --verbose 
antsApplyTransforms -d 3 -t translation.xfm -r sphere_volume.nii.gz -o [translation.nii.gz,1] --verbose

# XFM Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj translation.xfm sphere_translationXFM.obj

# MNC Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj translation.mnc sphere_translationMNC.obj

# NII.GZ Transform on OBJ Surface, using ants_transform_objects.sh
./../ants_transform_objects.sh sphere.obj translation.nii.gz sphere_translationNIIGZ.obj

# XFM Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj translation.xfm sphere_translationXFM_RAS_LPS.obj

# MNC Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj translation.mnc sphere_translationMNC_RAS_LPS.obj

# NII.GZ Transform on OBJ Surface, using ants_transform_objects_RAS_LPS_convert.sh
./../ants_transform_objects_RAS_LPS_convert.sh sphere.obj translation.nii.gz sphere_translationNIIGZ_RAS_LPS.obj

The XFM, MNC and NII.GZ transforms all perform the forward operation of moving the OBJ surface to the right, when applied with ants_transform_objects.sh (see below). As expected, the XFM, MNC and NII.GZ transforms all perform the inverse operation of moving the OBJ surface to the left, when applied with ants_transform_objects_RAS_LPS_convert.sh (see below).

translation_x_RAS translation_x_LPS

Figure: Original sphere (green), translated to the right when applied with ants_transform_objects.sh (top, yellow) or to the left when applied with ants_transform_objects_RAS_LPS_convert.sh (bottom, yellow)

Translating along the y-axis

Replacing param2xfm -translation 2 0 0 above with param2xfm -translation 0 2 0, you obtain similar results as to the ones for the translation along the x-axis. The XFM, MNC and NII.GZ transforms all perform the forward operation of moving the OBJ surface in the anterior direction, when applied with ants_transform_objects.sh (see below). As expected, the XFM, MNC and NII.GZ transforms all perform the inverse operation of moving the OBJ surface in the posterior direction, when applied with ants_transform_objects_RAS_LPS_convert.sh (see below).

translation_y_RAS translation_y_LPS

Figure: Original sphere (green), translated in the anterior direction when applied with ants_transform_objects.sh (top, yellow) or to the posterior direction when applied with ants_transform_objects_RAS_LPS_convert.sh (bottom, yellow)

Translating along the z-axis

Replacing param2xfm -translation 2 0 0 above with param2xfm -translation 0 0 2, you obtain similar results as to the ones for the translation along the x-axis. The XFM, MNC and NII.GZ transforms all perform the forward operation of moving the OBJ surface in the anterior direction, when applied with ants_transform_objects.sh (see below). As expected, the XFM, MNC and NII.GZ transforms all perform the inverse operation of moving the OBJ surface in the posterior direction, when applied with ants_transform_objects_RAS_LPS_convert.sh (see below).

translation_z

Figure: Original sphere (green), translated to the superior direction when applied with either or ants_transform_objects.sh (top, yellow) ants_transform_objects_RAS_LPS_convert.sh (bottom, yellow)

Clone this wiki locally