skimage2.transform.PolynomialTransform#
- class skimage2.transform.PolynomialTransform(params=None, *, dimensionality=None)[source]#
Bases:
_GeometricTransform2D polynomial transformation.
Has the following form:
X = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i )) Y = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i ))
- Parameters:
- paramsarray_like of shape (2, N), optional
Polynomial coefficients where
N * 2 = (order + 1) * (order + 2). So, a_ji is defined inparams[0, :]and b_ji inparams[1, :].- dimensionalityint, optional
Must have value 2 (the default) for polynomial transforms.
- Attributes:
- paramsndarray of shape (2, N)
Polynomial coefficients where
N * 2 = (order + 1) * (order + 2). So, a_ji is defined inparams[0, :]and b_ji inparams[1, :].
Examples
>>> import numpy as np >>> import _skimage2 as ski2
Define a transformation by estimation:
>>> src = [[-12.3705, -10.5075], ... [-10.7865, 15.4305], ... [8.6985, 10.8675], ... [11.4975, -9.5715], ... [7.8435, 7.4835], ... [-5.3325, 6.5025], ... [6.7905, -6.3765], ... [-6.1695, -0.8235]] >>> dst = [[0, 0], ... [0, 5800], ... [4900, 5800], ... [4900, 0], ... [4479, 4580], ... [1176, 3660], ... [3754, 790], ... [1024, 1931]] >>> tform = ski2.transform.PolynomialTransform.from_estimate(src, dst)
Calling the transform applies the transformation to the points:
>>> pts = tform(src) >>> np.allclose(pts, [[ 7.54, 12.27], ... [ 2.98, 5796.95], ... [4870.44, 5766.59], ... [4889.72, -6.72], ... [4515.62, 4617.5 ], ... [1183.25, 3694. ], ... [3767.57, 800.53], ... [ 998.02, 1881.97]], atol=0.01) True
- estimate(src, dst, order=2, weights=None)[source]#
Estimate the transformation from a set of corresponding points.
Deprecated since version 0.26:
estimateis deprecated since version 0.26 and will be removed in version 2.2. Please usePolynomialTransform.from_estimateclass constructor instead.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 = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i )) Y = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i ))
These equations can be transformed to the following form:
0 = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i )) - X 0 = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i )) - 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 = [[1 x y x**2 x*y y**2 ... 0 ... 0 -X] [0 ... 0 1 x y x**2 x*y y**2 -Y] ... ... ] x.T = [a00 a10 a11 a20 a21 a22 ... ann b00 b10 b11 b20 b21 b22 ... bnn 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.
Weights can be applied to each pair of corresponding points to indicate, particularly in an overdetermined system, if point pairs have higher or lower confidence or uncertainties associated with them. From the matrix treatment of least squares problems, these weight values are normalized, square-rooted, then built into a diagonal matrix, by which A is multiplied.
- Parameters:
- src(N, 2) array_like
Source coordinates.
- dst(N, 2) array_like
Destination coordinates.
- orderint, optional
Polynomial order (number of coefficients is order + 1).
- weights(N,) array_like, optional
Relative weight values for each pair of points.
- Returns:
- successbool
True, if model estimation succeeds.
- classmethod from_estimate(src, dst, order=2, weights=None)[source]#
Estimate the transformation from a set of corresponding points.
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 = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i )) Y = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i ))
These equations can be transformed to the following form:
0 = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i )) - X 0 = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i )) - 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 = [[1 x y x**2 x*y y**2 ... 0 ... 0 -X] [0 ... 0 1 x y x**2 x*y y**2 -Y] ... ... ] x.T = [a00 a10 a11 a20 a21 a22 ... ann b00 b10 b11 b20 b21 b22 ... bnn 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.
Weights can be applied to each pair of corresponding points to indicate, particularly in an overdetermined system, if point pairs have higher or lower confidence or uncertainties associated with them. From the matrix treatment of least squares problems, these weight values are normalized, square-rooted, then built into a diagonal matrix, by which A is multiplied.
- Parameters:
- srcarray_like of shape (N, 2)
Source coordinates.
- dstarray_like of shape (N, 2)
Destination coordinates.
- orderint, optional
Polynomial order (number of coefficients is order + 1).
- weightsarray_like of shape (N,), optional
Relative weight values for each pair of points.
- Returns:
- tfSelf or
FailedEstimation An instance of the transformation if the estimation succeeded. Otherwise, we return a special
FailedEstimationobject to signal a failed estimation. Testing the truth value of the failed estimation object will returnFalse. E.g.tf = PolynomialTransform.from_estimate(...) if not tf: raise RuntimeError(f"Failed estimation: {tf}")
- tfSelf or
- classmethod identity(dimensionality=None)[source]#
Identity transform
- Parameters:
- dimensionality{None, 2}, optional
This transform only allows dimensionality of 2, where None corresponds to 2. The parameter exists for compatibility with other transforms.
- Returns:
- tformtransform
Transform such that
np.all(tform(pts) == pts).
- property inverse#
Return a transform object representing the inverse.
- residuals(src, dst)[source]#
Determine residuals of transformed destination coordinates.
For each transformed source coordinate the Euclidean distance to the respective destination coordinate is determined.
- Parameters:
- srcndarray of shape (N, 2)
Source coordinates.
- dstndarray of shape (N, 2)
Destination coordinates.
- Returns:
- residualsndarray of shape (N,)
Residual for coordinate.