projectivetransform

ProjectiveTransform

class skimage.transform.ProjectiveTransform(matrix=None) [source]

Bases: skimage.transform._geometric.GeometricTransform

Matrix transformation.

Apply a projective transformation (homography) on coordinates.

For each homogeneous coordinate \mathbf{x} = [x, y, 1]^T, its target position is calculated by multiplying with the given matrix, H, to give H \mathbf{x}:

[[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 : (3, 3) array, optional

Homogeneous transformation matrix.

Attributes

params ((3, 3) array) Homogeneous transformation matrix.
__init__(matrix=None) [source]
estimate(src, dst) [source]

Set the transformation matrix with the explicit transformation parameters.

You can determine the over-, well- and under-determined parameters with the total least-squares method.

Number of source and destination coordinates must match.

The transformation is defined as:

X = (a0*x + a1*y + a2) / (c0*x + c1*y + 1)
Y = (b0*x + b1*y + b2) / (c0*x + c1*y + 1)

These equations can be transformed to the following form:

0 = a0*x + a1*y + a2 - c0*x*X - c1*y*X - X
0 = b0*x + b1*y + b2 - c0*x*Y - c1*y*Y - Y

which exist for each set of corresponding points, so we have a set of N * 2 equations. The coefficients appear linearly so we can write A x = 0, where:

A   = [[x y 1 0 0 0 -x*X -y*X -X]
       [0 0 0 x y 1 -x*Y -y*Y -Y]
        ...
        ...
      ]
x.T = [a0 a1 a2 b0 b1 b2 c0 c1 c3]

In case of total least-squares the solution of this homogeneous system of equations is the right singular vector of A which corresponds to the smallest singular value normed by the coefficient c3.

In case of the affine transformation the coefficients c0 and c1 are 0. Thus the system of equations is:

A   = [[x y 1 0 0 0 -X]
       [0 0 0 x y 1 -Y]
        ...
        ...
      ]
x.T = [a0 a1 a2 b0 b1 b2 c3]
Parameters:

src : (N, 2) array

Source coordinates.

dst : (N, 2) array

Destination coordinates.

Returns:

success : bool

True, if model estimation succeeds.

inverse(coords) [source]

Apply inverse transformation.

Parameters:

coords : (N, 2) array

Source coordinates.

Returns:

coords : (N, 2) array

Transformed coordinates.

doc_scikit_image
2017-01-12 17:22:53
Comments
Leave a Comment

Please login to continue.