IO
Reading and writing of transform files.
Base I/O
Read/write linear transforms.
- class nitransforms.io.base.BaseLinearTransformList(xforms=None, binaryblock=None, endianness=None, check=True)[source]
A string-based structure for series of linear transforms.
- property xforms
Get the list of internal transforms.
- class nitransforms.io.base.DisplacementsField[source]
A data structure representing displacements fields.
- class nitransforms.io.base.LinearParameters(parameters=None)[source]
A string-based structure for linear transforms.
Examples
>>> lp = LinearParameters() >>> np.array_equal(lp.structarr['parameters'], np.eye(4)) True
>>> p = np.diag([2., 2., 2., 1.]) >>> lp = LinearParameters(p) >>> np.array_equal(lp.structarr['parameters'], p) True
- class nitransforms.io.base.LinearTransformStruct(binaryblock=None, endianness=None, check=True)[source]
File data structure from linear transforms.
- class nitransforms.io.base.StringBasedStruct(binaryblock=None, endianness=None, check=True)[source]
File data structure from text files.
Tool Specific I/O
AFNI
Read/write AFNI’s transforms.
- class nitransforms.io.afni.AFNIDisplacementsField[source]
A data structure representing displacements fields.
- class nitransforms.io.afni.AFNILinearTransform(parameters=None)[source]
A string-based structure for AFNI linear transforms.
- classmethod from_ras(ras, moving=None, reference=None)[source]
Create an AFNI affine from a nitransform’s RAS+ matrix.
AFNI implicitly de-obliques image affine matrices before applying transforms, so for consistency we update the transform to account for the obliquity of the images.
>>> moving.affine == ras @ reference.affine
We can decompose the affines into oblique and de-obliqued components:
>>> moving.affine == m_obl @ m_deobl >>> reference.affine == r_obl @ r_deobl
To generate an equivalent AFNI transform, we need an effective transform (
e_ras
):>>> m_obl @ m_deobl == ras @ r_obl @ r_deobl >>> m_deobl == inv(m_obl) @ ras @ r_obl @ r_deobl
Hence,
>>> m_deobl == e_ras @ r_deobl >>> e_ras == inv(m_obl) @ ras @ r_obl
- class nitransforms.io.afni.AFNILinearTransformArray(xforms=None, binaryblock=None, endianness=None, check=True)[source]
A string-based structure for series of AFNI linear transforms.
FSL
Read/write FSL’s transforms.
- class nitransforms.io.fsl.FSLDisplacementsField[source]
A data structure representing displacements fields.
- class nitransforms.io.fsl.FSLLinearTransform(parameters=None)[source]
A string-based structure for FSL linear transforms.
- class nitransforms.io.fsl.FSLLinearTransformArray(xforms=None, binaryblock=None, endianness=None, check=True)[source]
A string-based structure for series of FSL linear transforms.
- classmethod from_filename(filename)[source]
Read the struct from a file given its path.
If the file does not exist, then indexed names with the zero-padded suffix
.NNN
are attempted, following FSL’s MCFLIRT conventions.
ITK
Read/write ITK transforms.
- class nitransforms.io.itk.ITKCompositeH5[source]
A data structure for ITK’s HDF5 files.
- class nitransforms.io.itk.ITKDisplacementsField[source]
A data structure representing displacements fields.
- class nitransforms.io.itk.ITKLinearTransform(parameters=None, offset=None)[source]
A string-based structure for ITK linear transforms.
- class nitransforms.io.itk.ITKLinearTransformArray(xforms=None, binaryblock=None, endianness=None, check=True)[source]
A string-based structure for series of ITK linear transforms.
- classmethod from_ras(ras, moving=None, reference=None)[source]
Create an ITK affine from a nitransform’s RAS+ matrix.
The moving and reference parameters are included in this method’s signature for a consistent API, but they have no effect on this particular method because ITK already uses RAS+ coordinates to describe transfroms internally.
- property xforms
Get the list of internal ITKLinearTransforms.
FreeSurfer/LTA
Read/write linear transforms.
- class nitransforms.io.lta.FSLinearTransform(binaryblock=None, endianness=None, check=True)[source]
Represents a single LTA’s transform structure.
- classmethod from_ras(ras, moving=None, reference=None)[source]
Create an affine from a nitransform’s RAS+ matrix.
- to_ras(moving=None, reference=None)[source]
Return a nitransforms’ internal RAS+ array.
Seemingly, the matrix of an LTA is defined such that it maps coordinates from the
dest volume
to thesrc volume
. Therefore, without inversion, the LTA matrix is appropiate to move the information fromsrc volume
into thedest volume
’s grid.Important
The
moving
andreference
parameters are dismissed becauseVOX2VOX
LTAs are converted toRAS2RAS
type before returning the RAS+ matrix, using thedest
andsrc
contained in the LTA. Both arguments are kept for API compatibility.- Parameters:
moving (dismissed) – The spatial reference of moving images.
reference (dismissed) – The spatial reference of moving images.
- Returns:
matrix – The RAS+ affine matrix corresponding to the LTA.
- Return type:
- class nitransforms.io.lta.FSLinearTransformArray(xforms=None, binaryblock=None, endianness=None, check=True)[source]
A list of linear transforms generated by FreeSurfer.