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 / EuclideanTransform

ABCMeta

skimage.transform._geometric:EuclideanTransform

source: /skimage/transform/_geometric.py

Signature

def EuclideanTransform(matrix = None, *, rotation = None, translation = None, dimensionality = None)

Summary

Euclidean transformation, also known as a rigid transform.

Extended Summary

Has the following form

X = a0 * x - b0 * y + a1 =
  = x * cos(rotation) - y * sin(rotation) + a1

Y = b0 * x + a0 * y + b1 =
  = x * sin(rotation) + y * cos(rotation) + b1

where the homogeneous transformation matrix is

[[a0 -b0  a1]
 [b0  a0  b1]
 [0   0   1 ]]

The Euclidean transformation is a rigid transformation with rotation and translation parameters. The similarity transformation extends the Euclidean transformation with a single scaling factor.

In 2D and 3D, the transformation parameters may be provided either via matrix, the homogeneous transformation matrix, above, or via the implicit parameters rotation and/or translation (where a1 is the translation along x, b1 along y, etc.). Beyond 3D, if the transformation is only a translation, you may use the implicit parameter translation; otherwise, you must use matrix.

The implicit parameters are applied in the following order:

  • Rotation;

  • Translation.

Parameters

matrix : array_like of shape (K, K), with K=D+1 (D being the dimensionality), optional

Homogeneous transformation matrix.

rotation : float or sequence of float, optional

Rotation angle, clockwise, in radians. If given as a vector, it is interpreted as Euler rotation angles [1]. Only 2D (single rotation) and 3D (Euler rotations) values are supported. For higher dimensions, you must provide or estimate the transformation matrix instead, and pass that as matrix above.

translation : (x, y[, z, ...]) sequence of float, length D, optional

Translation parameters for each axis.

dimensionality : int, optional

Fallback number of dimensions for transform when no other parameter is specified. Otherwise ignored, and we infer dimensionality from the input parameters.

Attributes

params : ndarray of shape (K, K), with K=D+1 (D being the dimensionality)

Homogeneous transformation matrix.

Examples

import numpy as np
import skimage as ski
✓
Define a transform with an homogeneous transformation matrix:
tform = ski.transform.EuclideanTransform(np.diag([2., 3., 1.]))
tform.params
✓
array([[2., 0., 0.],
       [0., 3., 0.],
       [0., 0., 1.]])
Define a transform with parameters:
tform = ski.transform.EuclideanTransform(
            rotation=0.2, translation=[1, 2])
np.round(tform.params, 2)
✓
array([[ 0.98, -0.2 ,  1.  ],
       [ 0.2 ,  0.98,  2.  ],
       [ 0.  ,  0.  ,  1.  ]])
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.EuclideanTransform.from_estimate(src, dst)
np.allclose(tform.params, [[ 0.99, 0.12,  16.77],
                           [-0.12, 0.99, 122.91],
                           [ 0.  , 0.  ,   1.  ]], atol=0.01)
✓
True
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.EuclideanTransform.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:EuclideanTransform[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'. EuclideanTransform: Poor conditioning for estimation

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.EuclideanTransform

Referenced by

This package