napari.utils.transforms.Affine#
- class napari.utils.transforms.Affine(scale=(1.0, 1.0), translate=(0.0, 0.0), *, affine_matrix=None, axis_labels: Sequence[str] | None = None, linear_matrix=None, name=None, ndim=None, rotate=None, shear=None, units: Sequence[str | Unit] | None = None)[source]#
Bases:
Transform
n-dimensional affine transformation class.
The affine transform can be represented as a n+1 dimensional transformation matrix in homogeneous coordinates [1], an n dimensional matrix and a length n translation vector, or be composed and decomposed from scale, rotate, and shear transformations defined in the following order:
rotate * shear * scale + translate
The affine_matrix representation can be used for easy compatibility with other libraries that can generate affine transformations.
- Parameters:
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
scale (1-D array) – A 1-D array of factors to scale each axis by. Scale is broadcast to 1 in leading dimensions, so that, for example, a scale of [4, 18, 34] in 3D can be used as a scale of [1, 4, 18, 34] in 4D without modification. An empty translation vector implies no scaling.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
translate (1-D array) – A 1-D array of factors to shift each axis by. Translation is broadcast to 0 in leading dimensions, so that, for example, a translation of [4, 18, 34] in 3D can be used as a translation of [0, 4, 18, 34] in 4D without modification. An empty translation vector implies no translation.
linear_matrix (n-D array, optional) – (N, N) matrix with linear transform. If provided then scale, rotate, and shear values are ignored.
affine_matrix (n-D array, optional) – (N+1, N+1) affine transformation matrix in homogeneous coordinates [1]. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
ndim (int) – The dimensionality of the transform. If None, this is inferred from the other parameters.
name (string) – A string name for the transform.
References
Methods
compose
()Return the composite of this transform and the provided one.
expand_dims
(axes)Return a transform with added axes for non-visible dimensions.
replace_slice
(axes, transform)Returns a transform where the transform at the indicated n dimensions is replaced with another n-dimensional transform
set_slice
(axes)Return a transform subset to the visible dimensions.
Attributes
Return the affine matrix for the transform.
tuple of axis labels for the layer.
changed
Return the inverse transform.
Return the linear matrix of the transform.
Dimensionality of the transform.
Return the scale of the transform, with units.
Return the rotation of the transform.
Return the scale of the transform.
Return the shear of the transform.
Return the translation of the transform.
List of units for the layer.
Details
- property affine_matrix: ndarray[Any, dtype[ScalarType]]#
Return the affine matrix for the transform.
- compose(transform: Affine) Affine [source]#
- compose(transform: Transform) Transform
Return the composite of this transform and the provided one.
- expand_dims(axes: Sequence[int]) Affine [source]#
Return a transform with added axes for non-visible dimensions.
- replace_slice(axes: Sequence[int], transform: Affine) Affine [source]#
Returns a transform where the transform at the indicated n dimensions is replaced with another n-dimensional transform