From ae6ef22a69ba6f7a31e6638a22083a8a5f87b80f Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 15 Apr 2012 23:53:53 -0400 Subject: [PATCH] Fix: return empty list for flat image. --- skimage/feature/peak.py | 2 ++ skimage/feature/tests/test_peak.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 30e1a84b..ebacfa3a 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -32,6 +32,8 @@ def peak_local_max(image, min_distance=10, threshold='deprecated', coordinates : (N, 2) array (row, column) coordinates of peaks. """ + if np.all(image == image.flat[0]): + return [] image = image.copy() # Non maximum filter size = 2 * min_distance + 1 diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index 7f960e3b..7fb090ba 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -36,6 +36,13 @@ def test_absolute_threshold(): assert len(peaks) == 1 assert_close(peaks, [(3, 3)]) + +def test_constant_image(): + image = 128 * np.ones((20, 20), dtype=np.uint8) + peaks = peak.peak_local_max(image, min_distance=1) + assert len(peaks) == 0 + + if __name__ == '__main__': from numpy import testing testing.run_module_suite()