{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / transform / _geometric / SimilarityTransform

ABCMeta

skimage.transform._geometric:SimilarityTransform

source: /dev/scikit-image/src/skimage/transform/_geometric.py :2073

Signature

def   SimilarityTransform ( matrix = None * scale = None rotation = None translation = None dimensionality = None )

Members

Summary

Similarity transformation.

Extended Summary

Has the following form in 2D

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

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

where s is a scale factor and the homogeneous transformation matrix is

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

The similarity transformation extends the Euclidean transformation with a single scaling factor in addition to the rotation and translation parameters.

The implicit parameters are applied in the following order:

  • Scale;

  • Rotation;

  • Translation.

Parameters

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

Homogeneous transformation matrix.

scale : float, optional

Scale factor. Implemented only for 2D and 3D.

rotation : float, optional

Rotation angle, clockwise, as radians. Implemented only for 2D and 3D. For 3D, this is given in ZYX Euler angles.

translation : array_like of shape (D,), optional

x, y[, z] translation parameters. Implemented only for 2D and 3D.

dimensionality : int, optional

The dimensionality of the transform, corresponding to D above. Ignored if matrix is not None, and set to matrix.shape[0] - 1. Otherwise, must be one of 2 or 3.

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.SimilarityTransform(np.diag([2., 3., 1.]))
tform.params
Define a transform with parameters:
tform = ski.transform.SimilarityTransform(
            rotation=0.2, translation=[1, 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.SimilarityTransform.from_estimate(src, dst)
np.allclose(tform.params, [[ 1.79, 0.21, -142.86],
                           [-0.21, 1.79,   21.43],
                           [ 0.  , 0.  ,    1.  ]], atol=0.01)
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.SimilarityTransform.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.SimilarityTransform

Referenced by