mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-23 13:10:18 +08:00
Fix RANSAC for invalid model estimation and confidence corner case
Previously, estimators did not return whether the model estimation was successful. RANSAC now tests whether the estimation was successful and skips invalid models. When the confidence/stop_probability of RANSAC was set to 1, the iteration was falsely terminated early instead of running for the maximum number of iterations.
This commit is contained in:
@@ -263,6 +263,11 @@ class ProjectiveTransform(GeometricTransform):
|
||||
dst : (N, 2) array
|
||||
Destination coordinates.
|
||||
|
||||
Returns
|
||||
-------
|
||||
success : bool
|
||||
True, if model estimation succeeds.
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
@@ -270,7 +275,7 @@ class ProjectiveTransform(GeometricTransform):
|
||||
dst_matrix, dst = _center_and_normalize_points(dst)
|
||||
except ZeroDivisionError:
|
||||
self.params = np.nan * np.empty((3, 3))
|
||||
return
|
||||
return False
|
||||
|
||||
xs = src[:, 0]
|
||||
ys = src[:, 1]
|
||||
@@ -309,6 +314,8 @@ class ProjectiveTransform(GeometricTransform):
|
||||
|
||||
self.params = H
|
||||
|
||||
return True
|
||||
|
||||
def __add__(self, other):
|
||||
"""Combine this transformation with another.
|
||||
|
||||
@@ -459,6 +466,11 @@ class PiecewiseAffineTransform(GeometricTransform):
|
||||
dst : (N, 2) array
|
||||
Destination coordinates.
|
||||
|
||||
Returns
|
||||
-------
|
||||
success : bool
|
||||
True, if model estimation succeeds.
|
||||
|
||||
"""
|
||||
|
||||
# forward piecewise affine
|
||||
@@ -481,6 +493,8 @@ class PiecewiseAffineTransform(GeometricTransform):
|
||||
affine.estimate(dst[tri, :], src[tri, :])
|
||||
self.inverse_affines.append(affine)
|
||||
|
||||
return True
|
||||
|
||||
def __call__(self, coords):
|
||||
"""Apply forward transformation.
|
||||
|
||||
@@ -658,6 +672,11 @@ class SimilarityTransform(ProjectiveTransform):
|
||||
dst : (N, 2) array
|
||||
Destination coordinates.
|
||||
|
||||
Returns
|
||||
-------
|
||||
success : bool
|
||||
True, if model estimation succeeds.
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
@@ -665,7 +684,7 @@ class SimilarityTransform(ProjectiveTransform):
|
||||
dst_matrix, dst = _center_and_normalize_points(dst)
|
||||
except ZeroDivisionError:
|
||||
self.params = np.nan * np.empty((3, 3))
|
||||
return
|
||||
return False
|
||||
|
||||
xs = src[:, 0]
|
||||
ys = src[:, 1]
|
||||
@@ -699,6 +718,7 @@ class SimilarityTransform(ProjectiveTransform):
|
||||
|
||||
self.params = S
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def scale(self):
|
||||
@@ -798,6 +818,11 @@ class PolynomialTransform(GeometricTransform):
|
||||
order : int, optional
|
||||
Polynomial order (number of coefficients is order + 1).
|
||||
|
||||
Returns
|
||||
-------
|
||||
success : bool
|
||||
True, if model estimation succeeds.
|
||||
|
||||
"""
|
||||
xs = src[:, 0]
|
||||
ys = src[:, 1]
|
||||
@@ -828,6 +853,8 @@ class PolynomialTransform(GeometricTransform):
|
||||
|
||||
self.params = params.reshape((2, u // 2))
|
||||
|
||||
return True
|
||||
|
||||
def __call__(self, coords):
|
||||
"""Apply forward transformation.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user