Fix: return empty list for flat image.

This commit is contained in:
Tony S Yu
2012-04-15 23:53:53 -04:00
parent 2585a323ac
commit ae6ef22a69
2 changed files with 9 additions and 0 deletions
+2
View File
@@ -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
+7
View File
@@ -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()