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()