Skip to content

Neuroimaging Informatics Technology Initiative

Sections
Personal tools
You are here: Home » NIfTI-1 Data Format » Documentation » NIfTI-1 Fields » nifti1fields_pages » Recommended usage of qform and sform

Recommended usage of qform and sform

Document Actions
A brief summary of the recommended usage of qforms and sforms in applications involving spatial transformations (especially registration).

THIS PAGE IS CURRENTLY UNDER CONSTRUCTION
Purpose of the qform and sform

The qform and sform stored in a nifti file are intended to fulfil the following functions:

  • specify the handedness of the coordinate system (important for getting left and right correct)
  • specify the original scanner coordinates (qform only; figure)
  • specify standard space coordinates (sform only)
  • specify a relationship with another image's coordinates (sform only)

The qform and sform should never specify coordinates with different handedness (i.e. have determinants of different signs). Otherwise it is not possible to tell left from right.

The qform_code should be set to either NIFTI_XFORM_UNKNOWN or NIFTI_XFORM_SCANNER_ANAT.

The sform code should be set to either NIFTI_XFORM_UNKNOWN, NIFTI_XFORM_ALIGNED_ANAT, NIFTI_XFORM_TALAIRACH or NIFTI_XFORM_MNI_152.


Using the qform and sform in applications

In applications that involve spatial transformations, it is not always clear how to use, copy of modify these fields. The following is a brief set of guidelines. A more detailed description also exists.

  1. Estimating a transformation (i.e. registration of two images without resampling):
    • the qform and/or sform of the two images may be used for initialising the alignment
    • the sform would normally be set to a transformed version of the target image's sform
       
      (e.g. estimating the transformation between an image and the MNI152 standard space template: afterwards the image would have its sform_code set to NIFTI_XFORM_MNI152 and the sform set to map the voxel coordinates from the image into the MNI152 standard coordinates)

     

  2. Resampling an image (i.e. applying a spatial transformation):
    • the resampled image should inherit a transformed version of the sform matrix (if it set originally) and the sform_code should remain the same
    • the qform of the resampled image need not be set (although a transformed version could be used)
    • if the resampling is non-linear (not affine) then both sform and qform should be set to NIFTI_XFORM_UNKNOWN

     

  3. Combined estimation and resampling (i.e. registration of two images with resampling):
    • the qform and/or sform of the two images may be used for initialising the alignment
    • the sform is set to a transformed version of the target image's sform
    • if the target image's sform is unknown, then apply the transformation to the original image's sform instead (by postmultiplication with the voxel-voxel transformation - see details on transformations)
  4. Applying a spatial transformation to a single image (i.e. not a registration of two images):
    • the qform and/or sform is postmultiplied by the transformation matrix relating the initial and final voxel coordinates (see details on transformations)
    • if the initial and final voxel coordinates do not have a known relationship then the qform and sform can be left unaltered (this might be an option available to the user)


Transforming the qform and sform

Consider applying a transformation which can be expressed as an affine mapping between voxel coordinates as:
  V' = A * V
where V' and V are column vectors representing voxel coordinates in the new and old image respectively, and A is an affine matrix.

The qform and sform matrices for the new image are given by:

  • sform' = sform * B
  • qform' = qform * B
where B is the inverse (matrix) of A

The above can only be used

  • for the qform when the transformation is rigid-body
  • for the sform when the transformation is affine
If the these conditions are not met then the new value of the qform or sform should be set to UNKNOWN.

For example:

  • applying an affine transformation can modify sform but should set the qform to UNKNOWN.
  • applying a non-linear transformation should set both qform and sform to UNKNOWN, unless a registration was performed in which case the sform should take the value of the target image's sform (as in a non-linear registration to a standard image)

If a single transformation is applied which would result in both qform and sform being set to unknown, the handedness of the coordinate system is lost. To avoid this, it is preferrable, when possible, to set the sform with a matrix that encodes the correct handedness (even if the coordinates themselves are not useful) and set the sform_code to NIFTI_XFORM_ALIGNED_ANAT.

For more information and examples, see the more detailed description.

Author: Mark Jenkinson

Created by Mark Jenkinson
Last modified 2005-05-17 11:16
 

Powered by Plone

This site conforms to the following standards: