napari.utils.transforms.Affine#

class napari.utils.transforms.Affine(scale=(1.0, 1.0), translate=(0.0, 0.0), *, rotate=None, shear=None, linear_matrix=None, affine_matrix=None, ndim=None, name=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

affine_matrix

Return the affine matrix for the transform.

changed

inverse

Return the inverse transform.

linear_matrix

Return the linear matrix of the transform.

ndim

Dimensionality of the transform.

rotate

Return the rotation of the transform.

scale

Return the scale of the transform.

shear

Return the shear of the transform.

translate

Return the translation of the transform.

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.

Parameters:

axes (Sequence[int]) – Location of axes to expand the current transform with. Passing a list allows expansion to occur at specific locations and for expand_dims to be like an inverse to the set_slice method.

Returns:

Resulting transform.

Return type:

Transform

property inverse: Affine#

Return the inverse transform.

property linear_matrix: ndarray[Any, dtype[ScalarType]]#

Return the linear matrix of the transform.

property ndim: int#

Dimensionality of the transform.

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

Parameters:
  • axes (Sequence[int]) – Axes where the transform will be replaced

  • transform (Affine) – The transform that will be inserted. Must have as many dimension as len(axes)

Returns:

Resulting transform.

Return type:

Affine

property rotate: ndarray[Any, dtype[ScalarType]]#

Return the rotation of the transform.

property scale: ndarray[Any, dtype[ScalarType]]#

Return the scale of the transform.

set_slice(axes: Sequence[int]) Affine[source]#

Return a transform subset to the visible dimensions.

Parameters:

axes (Sequence[int]) – Axes to subset the current transform with.

Returns:

Resulting transform.

Return type:

Affine

property shear: ndarray[Any, dtype[ScalarType]]#

Return the shear of the transform.

property translate: ndarray[Any, dtype[ScalarType]]#

Return the translation of the transform.