{ } Raw JSON

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, optional

Homogeneous 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}, optional

Scale 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, optional

The 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, optional

Rotation angle, clockwise, as radians. Only available for 2D.

translation : (tx, ty) as array, list or tuple, optional

Translation parameters. Only available for 2D.

dimensionality : int, optional

Fallback number of dimensions for transform when none of matrix, scale, rotation, shear or translation are specified. If any of scale, rotation, shear or translation are specified, must equal 2 (the default).

Raises

: ValueError

If both matrix and any of the other parameters are provided.

Attributes

params : (D+1, D+1) array

Homogeneous transformation matrix.

Examples

import numpy as np
import skimage as ski
Define a transform with an homogeneous transformation matrix:
tform = ski.transform.AffineTransform(np.diag([2., 3., 1.]))
tform.params
Define a transform with parameters:
tform = ski.transform.AffineTransform(scale=4, rotation=0.2)
np.round(tform.params, 2)
You can estimate a transformation to map between source and destination points:
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. ]])
Apply the transformation to some image data.
img = ski.data.astronaut()
warped = ski.transform.warp(img, inverse_map=tform.inverse)
The estimation can fail - for example, if all the input or output points are the same. If this happens, you will get a transform that is not "truthy" - meaning that ``bool(tform)`` is ``False``:
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.")
Trying to use this failed estimation transform result will give a suitable error:
bad_tform.params  # doctest: +IGNORE_EXCEPTION_DETAIL

Aliases

  • skimage.transform.AffineTransform

Referenced by

This package