diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 76f27a76..d3e3f4f5 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -3,7 +3,7 @@ import scipy.ndimage as ndi from ..filters import rank_order -def peak_local_max(image, min_distance=1, threshold_abs=0, +def peak_local_max(image, min_distance=1, threshold_abs=None, threshold_rel=None, exclude_border=True, indices=True, num_peaks=np.inf, footprint=None, labels=None): """Find peaks in an image as coordinate list or boolean mask. @@ -28,7 +28,8 @@ def peak_local_max(image, min_distance=1, threshold_abs=0, a border `min_distance` from the image boundary. To find the maximum number of peaks, use `min_distance=1`. threshold_abs : float, optional - Minimum intensity of peaks. + Minimum intensity of peaks. By default, the absolute threshold is + the minimum intensity of the image. threshold_rel : float, optional Minimum intensity of peaks, calculated as `max(image) * threshold_rel`. exclude_border : bool, optional @@ -93,9 +94,6 @@ def peak_local_max(image, min_distance=1, threshold_abs=0, """ - 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 @@ -150,8 +148,9 @@ def peak_local_max(image, min_distance=1, threshold_abs=0, # find top peak candidates above a threshold thresholds = [] - if threshold_abs is not None: - thresholds.append(threshold_abs) + if threshold_abs is None: + threshold_abs = image.min() + thresholds.append(threshold_abs) if threshold_rel is not None: thresholds.append(threshold_rel * image.max()) if thresholds: diff --git a/skimage/feature/tests/test_corner.py b/skimage/feature/tests/test_corner.py index 27f67b10..c3919fe8 100644 --- a/skimage/feature/tests/test_corner.py +++ b/skimage/feature/tests/test_corner.py @@ -269,19 +269,18 @@ def test_num_peaks(): def test_corner_peaks(): - response = np.zeros((5, 5)) - response[2:4, 2:4] = 1 + response = np.zeros((10, 10)) + response[2:5, 2:5] = 1 corners = corner_peaks(response, exclude_border=False, min_distance=10, threshold_rel=0) assert len(corners) == 1 - corners = corner_peaks(response, exclude_border=False, min_distance=0, - threshold_rel=0) + corners = corner_peaks(response, exclude_border=False, min_distance=1) assert len(corners) == 4 - corners = corner_peaks(response, exclude_border=False, min_distance=0, - threshold_rel=0, indices=False) + corners = corner_peaks(response, exclude_border=False, min_distance=1, + indices=False) assert np.sum(corners) == 4 diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index e6a08eef..8161ca39 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -272,11 +272,12 @@ def test_disk(): result = peak.peak_local_max(image, labels=np.ones((10, 20)), footprint=footprint, min_distance=1, threshold_rel=0, - indices=False, exclude_border=False) - assert np.all(result) - result = peak.peak_local_max(image, footprint=footprint, indices=False, + threshold_abs=-1, indices=False, exclude_border=False) assert np.all(result) + result = peak.peak_local_max(image, footprint=footprint, threshold_abs=-1, + indices=False, exclude_border=False) + assert np.all(result) def test_3D(): @@ -309,13 +310,6 @@ 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()