You should almost always call xform rather calling thanxformimage directly.

xformimage(reg, image, ...)

# S3 method for character
xformimage(reg, image, ...)

# S3 method for cmtkreg
xformimage(
reg,
image,
transformtype = c("warp", "affine"),
direction = NULL,
...
)

# S3 method for reglist
xformimage(reg, image, ...)

# S3 method for default
xformimage(reg, image, ...)

## Arguments

reg A registration defined by a matrix or a cmtkreg object, or a character vector specifying a path to a CMTK registration on disk (see details). If reg is a character vector of length >1 defining a sequence of registration files on disk they should proceed from sample to reference. Nx3 matrix of image Additional arguments passed to methods (and then eventually to cmtk.reformatx) Which transformation to use when the CMTK file contains both warp (default) and affine (TODO) Whether to transform image from sample space to reference space (called forward by CMTK) or from reference to sample space (called inverse by CMTK). Default (when NULL is forward).

## Value

Character vector with path to transformed image.

## Details

When passed a character vector, xformimage will check to see if it defines a path containing CMTK registration erroring out if this is not the case. If the path does indeed point to a CMTK registration, this method will hand off to xformimage.cmtkreg. A future TODO would be to provide a mechanism for extending this behaviour for other registration formats. If a list of transformations is passed in, these transformations are passed to the cmtk reformatx tool in the order received. Note that there is presently no support for

• using the inverse of a registration

• passing additional arguments to reformatx

Note that the direction of CMTK registrations can be the source of much confusion. This is because CMTK defines the forward direction as the transform required to reformat an image in sample (floating) space to an image in template space. Since this operation involves filling a regular grid in template space by looking up the corresponding positions in sample space, the transformation that is required is (somewhat counterintuitively) the one that maps template to sample. However in neuroanatomical work, one often has points in sample space that one would like to transform into template space. Here one needs CMTK's inverse transformation.

A second source of confusion is that when there are multiple transformations, CMTK's reformatx tool (wrapped by cmtk.reformatx) expects them to be listed:

ref_intermediate.list intermediate_sample.list

where ref_intermediate.list is the CMTK registration obtained with ref as target/reference and intermediate as sample/floating image.

For consistency, all xform.* methods expect multiple registrations to be listed from sample to reference and this order is then swapped when they are passed on to cmtk.reformatx.

whereas CMTK's streamxform tool (wrapped by xformpoints) expects them in the opposite order.

cmtk.reformatx, xformpoints, xform