mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-18 12:40:14 +08:00
MAINT change HT return API
This commit is contained in:
@@ -122,11 +122,11 @@ edges = filter.canny(image_gray, sigma=2.0,
|
||||
accum = hough_ellipse(edges, accuracy=10, threshold=170, min_size=50)
|
||||
accum.sort(key=lambda x:x[5])
|
||||
# Estimated parameters for the ellipse
|
||||
center_y = int(accum[-1][0])
|
||||
center_x = int(accum[-1][1])
|
||||
xradius = int(accum[-1][2])
|
||||
yradius = int(accum[-1][3])
|
||||
angle = np.pi - accum[-1][4]
|
||||
center_y = int(accum[-1][1])
|
||||
center_x = int(accum[-1][2])
|
||||
xradius = int(accum[-1][3])
|
||||
yradius = int(accum[-1][4])
|
||||
angle = np.pi - accum[-1][5]
|
||||
|
||||
# Draw the ellipse on the original image
|
||||
cx, cy = ellipse_perimeter(center_y, center_x,
|
||||
|
||||
@@ -122,7 +122,7 @@ def hough_ellipse(cnp.ndarray img, int threshold=4, double accuracy=1,
|
||||
|
||||
Returns
|
||||
-------
|
||||
res : list of tuples [(x0, y0, a, b, angle, accumulator)]
|
||||
res : list of tuples [(accumulator, x0, y0, a, b, angle)]
|
||||
Where (x0, y0) is the center, (a, b) major and minor axis.
|
||||
The angle value follows `draw.ellipse_perimeter()` convention.
|
||||
|
||||
@@ -132,7 +132,7 @@ def hough_ellipse(cnp.ndarray img, int threshold=4, double accuracy=1,
|
||||
>>> rr, cc = draw.ellipse_perimeter(10, 10, 6, 8)
|
||||
>>> img[cc, rr] = 1
|
||||
>>> result = hough_ellipse(img, threshold=8)
|
||||
[(10.0, 10.0, 8.0, 6.0, 0.0, 10)]
|
||||
[(10, 10.0, 10.0, 8.0, 6.0, 0.0)]
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -217,12 +217,12 @@ def hough_ellipse(cnp.ndarray img, int threshold=4, double accuracy=1,
|
||||
elif angle < - np.pi:
|
||||
angle = angle + np.pi / 2.
|
||||
b = sqrt(bin_edges[hist.argmax()])
|
||||
results.append((x0,
|
||||
results.append((hist_max, # Accumulator
|
||||
x0,
|
||||
y0,
|
||||
a,
|
||||
b,
|
||||
angle,
|
||||
hist_max, # Accumulator
|
||||
))
|
||||
acc = []
|
||||
|
||||
|
||||
@@ -157,11 +157,11 @@ def test_hough_ellipse_zero_angle():
|
||||
rr, cc = ellipse_perimeter(y0, x0, b, a)
|
||||
img[rr, cc] = 1
|
||||
result = tf.hough_ellipse(img, threshold=9)
|
||||
assert_equal(result[0][0], x0)
|
||||
assert_equal(result[0][1], y0)
|
||||
assert_almost_equal(result[0][2], b, decimal=1)
|
||||
assert_almost_equal(result[0][3], a, decimal=1)
|
||||
assert_equal(result[0][4], angle)
|
||||
assert_equal(result[0][1], x0)
|
||||
assert_equal(result[0][2], y0)
|
||||
assert_almost_equal(result[0][3], b, decimal=1)
|
||||
assert_almost_equal(result[0][4], a, decimal=1)
|
||||
assert_equal(result[0][5], angle)
|
||||
|
||||
|
||||
def test_hough_ellipse_non_zero_angle():
|
||||
@@ -174,11 +174,11 @@ def test_hough_ellipse_non_zero_angle():
|
||||
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] / 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)
|
||||
assert_almost_equal(result[0][1] / 100., x0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][2] / 100., y0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][3] / 10., b / 10., decimal=1)
|
||||
assert_almost_equal(result[0][4] / 100., a / 100., decimal=1)
|
||||
assert_almost_equal(result[0][5], angle, decimal=1)
|
||||
|
||||
|
||||
def test_hough_ellipse_non_zero_angle2():
|
||||
@@ -191,11 +191,11 @@ def test_hough_ellipse_non_zero_angle2():
|
||||
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][1] / 100., x0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][2] / 100., y0 / 100., decimal=1)
|
||||
assert_almost_equal(result[0][3] / 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)
|
||||
assert_almost_equal(result[0][5], angle, decimal=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user