From a3356194c8fccf2dabe37bb593964ac328d9078f Mon Sep 17 00:00:00 2001 From: "Josh Warner (Mac)" Date: Sat, 24 Oct 2015 23:58:29 -0500 Subject: [PATCH] TSTFIX: Fix imports in hough_ellipse doctest --- skimage/transform/_hough_transform.pyx | 3 -- skimage/transform/hough_transform.py | 9 ++++-- .../transform/tests/test_hough_transform.py | 32 +++++++++++++------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/skimage/transform/_hough_transform.pyx b/skimage/transform/_hough_transform.pyx index 3e4ba254..a189d7b9 100644 --- a/skimage/transform/_hough_transform.pyx +++ b/skimage/transform/_hough_transform.pyx @@ -12,9 +12,6 @@ from libc.stdlib cimport rand from ..draw import circle_perimeter -cdef double PI_2 = 1.5707963267948966 -cdef double NEG_PI_2 = -PI_2 - from .._shared.interpolation cimport round diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 72fcf61e..f9a8d2e5 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -59,7 +59,7 @@ def hough_line(img, theta=None): if theta is None: # These values are approximations of pi/2 - theta = np.linspace(-1.5707963267948966, 1.5707963267948966, 180) + theta = np.linspace(-np.pi / 2, np.pi / 2, 180) return _hough_line(img, theta=theta) @@ -225,7 +225,7 @@ def probabilistic_hough_line(img, threshold=10, line_length=50, line_gap=10, raise ValueError('The input image `img` must be 2D.') if theta is None: - theta = 1.5707963267948966 - np.arange(180) / 180.0 * np.pi + theta = np.pi / 2 - np.arange(180) / 180.0 * np.pi return _prob_hough_line(img, threshold=threshold, line_length=line_length, line_gap=line_gap, theta=theta) @@ -304,11 +304,14 @@ def hough_ellipse(img, threshold=4, accuracy=1, min_size=4, max_size=None): Examples -------- + >>> from skimage.transform import hough_ellipse + >>> from skimage.draw import ellipse_perimeter >>> img = np.zeros((25, 25), dtype=np.uint8) >>> rr, cc = ellipse_perimeter(10, 10, 6, 8) >>> img[cc, rr] = 1 >>> result = hough_ellipse(img, threshold=8) - [(10, 10.0, 8.0, 6.0, 0.0, 10.0)] + >>> result.tolist() + [(10, 10.0, 10.0, 8.0, 6.0, 0.0)] Notes ----- diff --git a/skimage/transform/tests/test_hough_transform.py b/skimage/transform/tests/test_hough_transform.py index 4877b38b..0babc769 100644 --- a/skimage/transform/tests/test_hough_transform.py +++ b/skimage/transform/tests/test_hough_transform.py @@ -1,5 +1,5 @@ import numpy as np -from numpy.testing import assert_almost_equal, assert_equal +from numpy.testing import assert_almost_equal, assert_equal, assert_raises import skimage.transform as tf from skimage.draw import line, circle_perimeter, ellipse_perimeter @@ -7,15 +7,6 @@ from skimage._shared._warnings import expected_warnings from skimage._shared.testing import test_parallel -def append_desc(func, description): - """Append the test function ``func`` and append - ``description`` to its name. - """ - func.description = func.__module__ + '.' + func.__name__ + description - - return func - - @test_parallel() def test_hough_line(): # Generate a test image @@ -42,12 +33,21 @@ def test_hough_line_angles(): assert_equal(len(angles), 10) +def test_hough_line_bad_input(): + img = np.zeros(100) + img[10] = 1 + + # Expected error, img must be 2D + assert_raises(ValueError, tf.hough_line, img, np.linspace(0, 360, 10)) + + def test_probabilistic_hough(): # Generate a test image img = np.zeros((100, 100), dtype=int) for i in range(25, 75): img[100 - i, i] = 100 img[i, i] = 100 + # decrease default theta sampling because similar orientations may confuse # as mentioned in article of Galambos et al theta = np.linspace(0, np.pi, 45) @@ -59,9 +59,21 @@ def test_probabilistic_hough(): line = list(line) line.sort(key=lambda x: x[0]) sorted_lines.append(line) + assert([(25, 75), (74, 26)] in sorted_lines) assert([(25, 25), (74, 74)] in sorted_lines) + # Execute with default theta + tf.probabilistic_hough_line(img, line_length=10, line_gap=3) + + +def test_probabilistic_hough_bad_input(): + img = np.zeros(100) + img[10] = 1 + + # Expected error, img must be 2D + assert_raises(ValueError, tf.probabilistic_hough_line, img) + def test_hough_line_peaks(): img = np.zeros((100, 150), dtype=int)