{ } Raw JSON

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

ABCMeta

skimage.transform._geometric:ProjectiveTransform

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

Signature

def   ProjectiveTransform ( matrix = None * dimensionality = None )

Members

Summary

Projective transformation.

Extended Summary

Apply a projective transformation (homography) on coordinates.

For each homogeneous coordinate , its target position is calculated by multiplying with the given matrix, , to give :

[[a0 a1 a2]
 [b0 b1 b2]
 [c0 c1 1 ]].

E.g., to rotate by theta degrees clockwise, the matrix should be

[[cos(theta) -sin(theta) 0]
 [sin(theta)  cos(theta) 0]
 [0            0         1]]

or, to translate x by 10 and y by 20

[[1 0 10]
 [0 1 20]
 [0 0 1 ]].

Parameters

matrix : (D+1, D+1) array_like, optional

Homogeneous transformation matrix.

dimensionality : int, optional

Fallback number of dimensions when matrix not specified.

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.ProjectiveTransform(np.diag([2., 3., 1.]))
tform.params
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.ProjectiveTransform.from_estimate(src, dst)
np.allclose(tform.params, [[ -16.56,    5.82,  895.81],
                           [ -10.31,   -8.29, 2075.43],
                           [  -0.05,    0.02,    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.ProjectiveTransform.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.ProjectiveTransform

Referenced by