Skip to content

Commit

Permalink
Fix IndexError when calling hough_line_peaks with too few angles (sci…
Browse files Browse the repository at this point in the history
…kit-image#5024)

Fixes scikit-imagegh-4814

Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
  • Loading branch information
cjblocker and rfezzani authored Oct 27, 2020
1 parent 06f6a12 commit e13e596
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions skimage/transform/hough_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def hough_line_peaks(hspace, angles, dists, min_distance=9, min_angle=10,
"""
from ..feature.peak import _prominent_peaks

min_angle = min(min_angle, hspace.shape[1])
h, a, d = _prominent_peaks(hspace, min_xdistance=min_angle,
min_ydistance=min_distance,
threshold=threshold,
Expand Down
9 changes: 9 additions & 0 deletions skimage/transform/tests/test_hough_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def test_hough_line_peaks_zero_input():
assert_equal(a, np.array([]))


def test_hough_line_peaks_single_angle():
# Regression test for gh-4814
# This code snippet used to raise an IndexError
img = np.random.random((100, 100))
tested_angles = np.array([np.pi / 2])
h, theta, d = transform.hough_line(img, theta=tested_angles)
accum, angles, dists = transform.hough_line_peaks(h, theta, d, threshold=2)


@test_parallel()
def test_hough_circle():
# Prepare picture
Expand Down

0 comments on commit e13e596

Please sign in to comment.