mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-19 11:27:45 +08:00
FIX: fix angle convention
This commit is contained in:
@@ -206,9 +206,16 @@ def hough_ellipse(cnp.ndarray img, int threshold=4, double accuracy=1,
|
||||
hist_max = np.max(hist)
|
||||
if hist_max > threshold:
|
||||
angle = np.arctan2(p1x - p2x, p1y - p2y)
|
||||
# pi - angle to keep ellipse_perimeter() convention
|
||||
# to keep ellipse_perimeter() convention
|
||||
if angle != 0:
|
||||
angle = np.pi - angle
|
||||
# When angle is not in [-pi:pi]
|
||||
# it would mean in ellipse_perimeter()
|
||||
# that a < b. But we keep a > b.
|
||||
if angle > np.pi:
|
||||
angle = angle - np.pi / 2.
|
||||
elif angle < - np.pi:
|
||||
angle = angle + np.pi / 2.
|
||||
b = sqrt(bin_edges[hist.argmax()])
|
||||
results.append((x0,
|
||||
y0,
|
||||
|
||||
@@ -165,9 +165,9 @@ def test_hough_ellipse_zero_angle():
|
||||
|
||||
|
||||
def test_hough_ellipse_non_zero_angle():
|
||||
img = np.zeros((30, 20), dtype=int)
|
||||
img = np.zeros((30, 24), dtype=int)
|
||||
a = 6
|
||||
b = 9
|
||||
b = 12
|
||||
x0 = 10
|
||||
y0 = 15
|
||||
angle = np.pi / 1.35
|
||||
@@ -176,10 +176,27 @@ def test_hough_ellipse_non_zero_angle():
|
||||
result = tf.hough_ellipse(img, threshold=15, accuracy=3)
|
||||
assert_almost_equal(result[0][0] / 100., x0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][1] / 100., y0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][2] / 100., b / 100., decimal=1)
|
||||
assert_almost_equal(result[0][2] / 10., b / 10., decimal=1)
|
||||
assert_almost_equal(result[0][3] / 100., a / 100., decimal=1)
|
||||
assert_almost_equal(result[0][4], angle, decimal=1)
|
||||
|
||||
|
||||
def test_hough_ellipse_non_zero_angle2():
|
||||
img = np.zeros((30, 24), dtype=int)
|
||||
b = 6
|
||||
a = 12
|
||||
x0 = 10
|
||||
y0 = 15
|
||||
angle = np.pi / 1.35
|
||||
rr, cc = ellipse_perimeter(y0, x0, b, a, orientation=angle)
|
||||
img[rr, cc] = 1
|
||||
result = tf.hough_ellipse(img, threshold=15, accuracy=3)
|
||||
assert_almost_equal(result[0][0] / 100., x0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][1] / 100., y0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][2] / 100., a / 100., decimal=1)
|
||||
assert_almost_equal(result[0][3] / 100., b / 100., decimal=1)
|
||||
assert_almost_equal(result[0][4], angle, decimal=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
np.testing.run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user