surfa.Affine
surfa.Affine#
- class surfa.Affine(matrix, source=None, target=None, space=None)#
N-D transform, represented by an (N+1, N+1) affine matrix, that tracks source and target geometries as well as coordinate space.
- Parameters
matrix ((N, N) or (N, N+1) float) – 2D or 3D linear transformation matrix.
source (castable ImageGeometry) – Transform source (or moving) image geometry.
target (castable ImageGeometry) – Transform target (or fixed) image geometry.
space (Space) – Coordinate space of the transform.
Attributes
matrix
The (N, N) affine matrix array.
ndim
Dimensionality of the transform.
source
Source (or moving) image geometry.
space
Coordinate space of the transform.
target
Target (or fixed) image geometry.
Methods
- convert(source=None, target=None, space=None, copy=True)#
Convert affine for a new coordinate space. Since original geometry and coordinate information is required for conversion, an error will be thrown if the source, target, and space have not been defined for the transform.
- Parameters
source (ImageGeometry, Image, or Surface) – Transform source and target image geometries.
target (ImageGeometry, Image, or Surface) – Transform source and target image geometries.
space (Space) – Coordinate space of the transform.
copy (bool) – Return copy of object if conditions are already satisfied.
- Returns
Converted affine transform.
- Return type
float
- copy()#
Return a copy of the affine.
- decompose(degrees=True)#
Decompose the affine matrix into a set of translation, rotation, scale and shear components.
- Parameters
degrees (bool) – Return rotation in degrees instead of radians.
- Returns
Tuple of (translation, rotation, scale, shear) transform components.
- Return type
tuple
- det()#
Compute the affine matrix determinant.
- Returns
Determinant.
- Return type
float
- inv()#
Compute the inverse linear transform, reversing source and target information.
- Returns
Inverted affine transform.
- Return type
- new(matrix)#
Return a new instance of the affine with an updated matrix and preserved metadata.
- save(filename)#
Save affine transform to file.
- Parameters
filename (str) – Target filename.
- to_warp(format=None)#
Convert affine transform to a dense warp field.
- Parameters
format (Warp.Format, optional) – Output warp field format.
- Returns
Dense transformation field.
- Return type
Warp
- transform(data, method='linear', rotation='corner', resample=True, fill=0, points=None)#
Apply the affine transform matrix to the input data.
- Parameters
data ((..., N) float or Volume) – Input coordinates or image to transform.
method ({'linear', 'nearest'}) – Image interpolation method if resample is enabled.
rotation ({'corner', 'center'}) – Apply affine with rotation axis at the image corner or center.
resample (bool) – If enabled, voxel data will be interpolated and resampled, and geometry will be set the target. If disabled, voxel data will not be modified, and only the geometry will be updated (this is not possible if a displacement field is provided).
fill (scalar) – Fill value for out-of-bounds voxels.
points (N-D point values) – Deprecated. Use the data argument instead.
- Returns
Transformed N-D point array if the input is N-D point data, or transformed image if the input is an image.
- Return type
(…, N) float or Volume