From a87779b650e4fa1e6abd08510d2dc241e6fd9dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 10 Aug 2012 20:45:50 +0200 Subject: [PATCH 1/2] fix num_peaks parameter bug in peak_local_max --- skimage/feature/peak.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index d8e54dd6..57eb3bb7 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -95,9 +95,9 @@ def peak_local_max(image, min_distance=10, threshold='deprecated', # get coordinates of peaks coordinates = np.transpose(image_t.nonzero()) - if len(coordinates) > num_peaks: - intensities = image[tuple(coordinates.T)] + if coordinates.shape[0] > num_peaks: + intensities = image[coordinates[:, 0], coordinates[:, 1]] idx_maxsort = np.argsort(intensities)[::-1] - coordinates = coordinates[idx_maxsort][:2] + coordinates = coordinates[idx_maxsort][:num_peaks] return coordinates From bb27e3771053c05e67b4045b7b91a78b6419afbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 14 Aug 2012 07:59:54 +0200 Subject: [PATCH 2/2] extend test cases for num_peaks parameter of peak_local_max --- skimage/feature/tests/test_peak.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index eaedc84f..13457781 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -51,15 +51,23 @@ def test_flat_peak(): def test_num_peaks(): - image = np.zeros((3, 7), dtype=np.uint8) + image = np.zeros((7, 7), dtype=np.uint8) image[1, 1] = 10 image[1, 3] = 11 image[1, 5] = 12 - assert len(peak.peak_local_max(image, min_distance=1)) == 3 + image[3, 5] = 8 + image[5, 3] = 7 + assert len(peak.peak_local_max(image, min_distance=1)) == 5 peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=2) assert len(peaks_limited) == 2 assert (1, 3) in peaks_limited assert (1, 5) in peaks_limited + peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=4) + assert len(peaks_limited) == 4 + assert (1, 3) in peaks_limited + assert (1, 5) in peaks_limited + assert (1, 1) in peaks_limited + assert (3, 5) in peaks_limited if __name__ == '__main__':