bundles / skimage 0.26.1rc0.dev0 / skimage / transform / _geometric / ProjectiveTransform
ABCMeta
skimage.transform._geometric:ProjectiveTransform
source: /skimage/transform/_geometric.py
Signature
def ProjectiveTransform(matrix = None, *, dimensionality = None)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, optionalHomogeneous transformation matrix.
dimensionality: int, optionalFallback number of dimensions when
matrixnot specified.
Attributes
params: (D+1, D+1) arrayHomogeneous transformation matrix.
Examples
import numpy as np import skimage as ski✓
tform = ski.transform.ProjectiveTransform(np.diag([2., 3., 1.])) tform.params✓
array([[2., 0., 0.],
[0., 3., 0.],
[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.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)✓
TrueApply the transformation to some image data.
img = ski.data.astronaut() warped = ski.transform.warp(img, inverse_map=tform.inverse)✓
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.")✓
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:ProjectiveTransform[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'. ProjectiveTransform: 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.ProjectiveTransform