Obtain or replace the “xform” transforms for an image

Share:

Description

These functions convert the “qform” or “sform” information in a NIfTI header to or from a corresponding affine matrix. These two “xform” mechanisms are defined by the NIfTI standard, and may both be in use in a particular image header.

Usage

1
2
3
4
5
xform(image, useQuaternionFirst = TRUE)

qform(x) <- value

sform(x) <- value

Arguments

image, x

An image, in any acceptable form (see retrieveNifti).

useQuaternionFirst

A single logical value. If TRUE, the “qform” matrix will be used first, if it is defined; otherwise the “sform” matrix will take priority.

value

A new 4x4 qform or sform matrix. If the matrix has a "code" attribute, the appropriate qform or sform code is also set.

Value

A affine matrix corresponding to the “qform” or “sform” information in the image header. This is a plain matrix, which does not have the "affine" class or source and target attributes.

Note

The qform and sform replacement functions are for advanced users only. Modifying the transforms without knowing what you're doing is usually unwise, as you can make the image object inconsistent.

Author(s)

Jon Clayden <code@clayden.org>

References

The NIfTI-1 standard (http://nifti.nimh.nih.gov/nifti-1) is the definitive reference on “xform” conventions.

Examples

1
2
3
4
5
6
7
8
im <- readNifti(system.file("extdata", "example.nii.gz", package="RNifti"))
xform(im)

# Remove the qform information
qform(im) <- structure(diag(4), code=0L)

# The same as above, since the sform is unmodified
xform(im)