bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / transform / _geometric / AffineTransform
ABCMeta
skimage.transform._geometric:AffineTransform
source: /dev/scikit-image/src/skimage/transform/_geometric.py :1327
Signature
def AffineTransform ( matrix = None , * , scale = None , shear = None , rotation = None , translation = None , dimensionality = None ) Members
Summary
Affine transformation.
Extended Summary
Has the following form
X = a0 * x + a1 * y + a2 = sx * x * [cos(rotation) + tan(shear_y) * sin(rotation)] - sy * y * [tan(shear_x) * cos(rotation) + sin(rotation)] + translation_x Y = b0 * x + b1 * y + b2 = sx * x * [sin(rotation) - tan(shear_y) * cos(rotation)] - sy * y * [tan(shear_x) * sin(rotation) - cos(rotation)] + translation_y
where sx and sy are scale factors in the x and y directions.
This is equivalent to applying the operations in the following order:
Scale
Shear
Rotate
Translate
The homogeneous transformation matrix is
[[a0 a1 a2] [b0 b1 b2] [0 0 1]]
In 2D, the transformation parameters can be given as the homogeneous transformation matrix, above, or as the implicit parameters, scale, rotation, shear, and translation in x (a2) and y (b2). For 3D and higher, only the matrix form is allowed.
In narrower transforms, such as the Euclidean (only rotation and translation) or Similarity (rotation, translation, and a global scale factor) transforms, it is possible to specify 3D transforms using implicit parameters also.
Parameters
matrix: (D+1, D+1) array_like, optionalHomogeneous transformation matrix. If this matrix is provided, it is an error to provide any of scale, rotation, shear, or translation.
scale: {s as float or (sx, sy) as array, list or tuple}, optionalScale factor(s). If a single value, it will be assigned to both sx and sy. Only available for 2D.
shear: float or 2-tuple of float, optionalThe x and y shear angles, clockwise, by which these axes are rotated around the origin [2]. If a single value is given, take that to be the x shear angle, with the y angle remaining 0. Only available in 2D.
rotation: float, optionalRotation angle, clockwise, as radians. Only available for 2D.
translation: (tx, ty) as array, list or tuple, optionalTranslation parameters. Only available for 2D.
dimensionality: int, optionalFallback number of dimensions for transform when none of
matrix,scale,rotation,shearortranslationare specified. If any ofscale,rotation,shearortranslationare specified, must equal 2 (the default).
Raises
: ValueErrorIf both
matrixand any of the other parameters are provided.
Attributes
params: (D+1, D+1) arrayHomogeneous transformation matrix.
Examples
import numpy as np import skimage as ski✓
tform = ski.transform.AffineTransform(np.diag([2., 3., 1.])) tform.params✓
tform = ski.transform.AffineTransform(scale=4, rotation=0.2) np.round(tform.params, 2)✓
src = np.array([[150, 150], [250, 100], [150, 200]]) dst = np.array([[200, 200], [300, 150], [150, 400]]) tform = ski.transform.AffineTransform.from_estimate(src, dst) np.allclose(tform.params, [[ 0.5, -1. , 275. ], [ 1.5, 4. , -625. ], [ 0. , 0. , 1. ]])✓
img = ski.data.astronaut() warped = ski.transform.warp(img, inverse_map=tform.inverse)✓
if tform: print("Estimation succeeded.") bad_src = np.ones((3, 2)) bad_tform = ski.transform.AffineTransform.from_estimate( bad_src, dst) if not bad_tform: print("Estimation failed.")✓
bad_tform.params # doctest: +IGNORE_EXCEPTION_DETAIL
✓Aliases
-
skimage.transform.AffineTransform