This is a development version (0.26.1rc0.dev0) and may be unstable.Go to latest (0.26.1rc0.dev0+git20260530.b607368ff)
{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0 / skimage / transform / _geometric / PiecewiseAffineTransform

ABCMeta

skimage.transform._geometric:PiecewiseAffineTransform

source: /skimage/transform/_geometric.py

Signature

def PiecewiseAffineTransform()

Summary

Piecewise affine transformation.

Extended Summary

Control points are used to define the mapping. The transform is based on a Delaunay triangulation of the points to form a mesh. Each triangle is used to find a local affine transform.

Attributes

affines : list of AffineTransform objects

Affine transformations for each triangle in the mesh.

inverse_affines : list of AffineTransform objects

Inverse affine transformations for each triangle in the mesh.

Examples

import numpy as np
import skimage as ski
✓
Define a transformation by estimation:
src = [[-12.3705, -10.5075],
       [-10.7865, 15.4305],
       [8.6985, 10.8675],
       [11.4975, -9.5715],
       [7.8435, 7.4835],
       [-5.3325, 6.5025],
       [6.7905, -6.3765],
       [-6.1695, -0.8235]]
dst = [[0, 0],
       [0, 5800],
       [4900, 5800],
       [4900, 0],
       [4479, 4580],
       [1176, 3660],
       [3754, 790],
       [1024, 1931]]
tform = ski.transform.PiecewiseAffineTransform.from_estimate(src, dst)
✓
Calling the transform applies the transformation to the points:
np.allclose(tform(src), dst)
✓
True
You can apply the inverse transform:
np.allclose(tform.inverse(dst), src)
✓
True
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 = [[1, 1]] * 6 + src[6:]
bad_tform = ski.transform.PiecewiseAffineTransform.from_estimate(
     bad_src, dst)
if not bad_tform:
    print("Estimation failed.")
✓
Estimation failed.
Trying to use this failed estimation transform result will give a suitable error:
bad_tform.params  # doctest: +IGNORE_EXCEPTION_DETAIL
✓
Traceback (most recent call last):
  File "<doctest skimage.transform._geometric:PiecewiseAffineTransform[0]>", line 1, in <module>
    bad_tform.params  # doctest: +IGNORE_EXCEPTION_DETAIL
    ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.7/x64/lib/python3.14/site-packages/_skimage2/_shared/utils.py", line 546, in __getattr__
    raise self.error_cls(msg)
_skimage2._shared.utils.FailedEstimationAccessError: FailedEstimation has no attribute 'params'. PiecewiseAffineTransform: Failure at inverse simplex 0: AffineTransform: Scaling generated NaN values; Failure at inverse simplex 1: AffineTransform: Scaling generated NaN values; Failure at inverse simplex 2: AffineTransform: Scaling generated NaN values

Hint: You can check for a failed estimation by truth testing the returned object. For failed estimations, `bool(estimation_result)` will be `False`. E.g.

    if not estimation_result:
        raise RuntimeError(f'Failed estimation: {estimation_result}')

Aliases

  • skimage.transform.PiecewiseAffineTransform