diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 4366923f..8aaf9119 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -19,7 +19,7 @@ def peak_local_max(image, min_distance=1, threshold_abs=None, Parameters ---------- - image : ndarray of floats + image : ndarray Input image. min_distance : int, optional Minimum number of pixels separating peaks in a region of `2 * @@ -93,6 +93,9 @@ def peak_local_max(image, min_distance=1, threshold_abs=None, """ + if min_distance < 1: + raise ValueError("`min_disance` must greater than 0") + out = np.zeros_like(image, dtype=np.bool) # In the case of labels, recursively build and return an output diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index 43a87369..e6a08eef 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -1,6 +1,6 @@ import numpy as np from numpy.testing import (assert_array_almost_equal as assert_close, - assert_equal) + assert_equal, assert_raises) from scipy import ndimage as ndi from skimage.feature import peak @@ -309,6 +309,13 @@ def test_4D(): [[5, 5, 5, 5], [15, 15, 15, 15]]) +def test_invalid_min_distance(): + assert_raises(ValueError, peak.peak_local_max, np.zeros((10, 10)), + min_distance=0) + assert_raises(ValueError, peak.peak_local_max, np.zeros((10, 10)), + min_distance=-1) + + if __name__ == '__main__': from numpy import testing testing.run_module_suite()