fsl.transform.flirt
This module contains functions for working with FLIRT affine transformation matrices. The following functions are available:
Reads a FLIRT matrix from a file. |
|
Writes the given FLIRT matrix to a file. |
|
Convert a FLIRT affine matrix into another affine. |
|
Convert an affine matrix into a FLIRT matrix. |
|
Converts the given |
|
Under the assumption that the given |
FLIRT transformation matrices are affine matrices of shape (4, 4)
which
encode a linear transformation from a source image to a reference image. FLIRT
matrices are defined in terms of FSL coordinates, which is a coordinate
system where voxels are scaled by pixdims, and with a left-right flip if the
image sform
has a positive determinant.
FLIRT matrices thus encode a transformation from source image FSL coordinates to reference image FSL coordinates.
- fsl.transform.flirt.fromFlirt(xform, src, ref, from_='voxel', to='world')[source]
Convert a FLIRT affine matrix into another affine.
Given a FLIRT matrix, and the source and reference images with which the FLIRT matrix is associated, converts the matrix into an affine matrix which can transform coordinates from the source image
from_
coordinate system to the reference imageto
coordinate system.The
from_
andto
arguments specify the desired spaces that the returned affine should transform between. The default values (from_='voxel'
andto='world'
will generate an affine which transforms from voxels in the source image to world-coordinates in the reference image.Valid values for the
from_
andto
arguments are:voxel
: The voxel coordinate systemfsl
: The FSL coordinate system (voxels scaled by pixdims, with the X axis inverted if the image sform/qform has a positive determinant)world
The world coordinate system
See the
Nifti
class documentation and theNifti.getAffine()
method for more details.- Parameters:
- Returns:
numpy
array of shape(4, 4)
containing a matrix encoding a transformation from the sourcefrom_
to the referenceto
coordinate systems.
- fsl.transform.flirt.toFlirt(xform, src, ref, from_='voxel', to='world')[source]
Convert an affine matrix into a FLIRT matrix.
- Returns:
numpy
array of shape(4, 4)
containing a matrix encoding a transformation from the sourcefrom_
to the referenceto
coordinate systems.- Parameters:
- Returns:
A
numpy
array of shape(4, 4)
containing a FLIRT transformation matrix fromsrc
toref
.
- fsl.transform.flirt.flirtMatrixToSform(flirtMat, srcImage, refImage)[source]
Converts the given
FLIRT
transformation matrix into a transformation from the source image voxel coordinate system to the reference image world coordinate system.To construct a transformation from source image voxel coordinates into reference image world coordinates, we need to combine the following:
Source voxels -> Source scaled voxels
Source scaled voxels -> Reference scaled voxels (the FLIRT matrix)
Reference scaled voxels -> Reference voxels
Reference voxels -> Reference world (the reference image sform)
- fsl.transform.flirt.sformToFlirtMatrix(srcImage, refImage, srcXform=None)[source]
Under the assumption that the given
srcImage
andrefImage
share a common world coordinate system (defined by theirNifti.voxToWorldMat
attributes), this function will calculate and return a transformation matrix from thesrcImage
FSL coordinate system to therefImage
FSL coordinate system, that can be saved to disk and used with FLIRT, to resample the source image to the space of the reference image.- Parameters:
srcImage – Source
Image
refImage – Reference
Image
srcXform – Optionally used in place of the
srcImage
Nifti.voxToWorldMat