From c815bd6030c1091f10f27cab9ead2ba88b65996d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 10 Mar 2014 08:11:53 -0400 Subject: [PATCH 1/3] Fix peak_local_max doc string --- skimage/feature/peak.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 3268831a..378d22b4 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -49,9 +49,9 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, Returns ------- - output : (N, 2) array or ndarray of bools + output : ndarray or ndarray of bools - * If `indices = True` : (row, column) coordinates of peaks. + * If `indices = True` : (row, column, ...) coordinates of peaks. * If `indices = False` : Boolean array shaped like `image`, with peaks represented by True values. @@ -65,10 +65,10 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, Examples -------- - >>> im = np.zeros((7, 7)) - >>> im[3, 4] = 1 - >>> im[3, 2] = 1.5 - >>> im + >>> img1 = np.zeros((7, 7)) + >>> img1[3, 4] = 1 + >>> img1[3, 2] = 1.5 + >>> img1 array([[ 0. , 0. , 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. , 0. , 0. ], @@ -77,13 +77,18 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, [ 0. , 0. , 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. , 0. , 0. ]]) - >>> peak_local_max(im, min_distance=1) + >>> peak_local_max(img1, min_distance=1) array([[3, 2], [3, 4]]) - >>> peak_local_max(im, min_distance=2) + >>> peak_local_max(img1, min_distance=2) array([[3, 2]]) + >>> img2 = np.zeros((20, 20, 20)) + >>> img2[10, 10, 10] = 1 + >>> peak_local_max(img2, exclude_border=False) + array([[10, 10, 10]]) + """ out = np.zeros_like(image, dtype=np.bool) # In the case of labels, recursively build and return an output From 438784cdda982be146edb0b0a2bdd9ea71b69996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 10 Mar 2014 08:20:32 -0400 Subject: [PATCH 2/3] Add test case for 3D images --- skimage/feature/tests/test_peak.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index 1a3e91f2..5e03018b 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -1,5 +1,6 @@ import numpy as np -from numpy.testing import assert_array_almost_equal as assert_close +from numpy.testing import (assert_array_almost_equal as assert_close, + assert_equal) import scipy.ndimage from skimage.feature import peak @@ -266,6 +267,18 @@ def test_disk(): assert np.all(result) +def test_3D(): + image = np.zeros((30, 30, 30)) + image[15, 15, 15] = 1 + image[5, 5, 5] = 1 + assert_equal(peak.peak_local_max(image), [[15, 15, 15]]) + assert_equal(peak.peak_local_max(image, min_distance=6), [[15, 15, 15]]) + assert_equal(peak.peak_local_max(image, exclude_border=False), + [[5, 5, 5], [15, 15, 15]]) + assert_equal(peak.peak_local_max(image, min_distance=5), + [[5, 5, 5], [15, 15, 15]]) + + if __name__ == '__main__': from numpy import testing testing.run_module_suite() From cd13361b1109ff5932b34a8dbb0e8e84abbc8db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 10 Mar 2014 08:21:50 -0400 Subject: [PATCH 3/3] Add test case for 4D images --- skimage/feature/tests/test_peak.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index 5e03018b..98242a4d 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -279,6 +279,18 @@ def test_3D(): [[5, 5, 5], [15, 15, 15]]) +def test_4D(): + image = np.zeros((30, 30, 30, 30)) + image[15, 15, 15, 15] = 1 + image[5, 5, 5, 5] = 1 + assert_equal(peak.peak_local_max(image), [[15, 15, 15, 15]]) + assert_equal(peak.peak_local_max(image, min_distance=6), [[15, 15, 15, 15]]) + assert_equal(peak.peak_local_max(image, exclude_border=False), + [[5, 5, 5, 5], [15, 15, 15, 15]]) + assert_equal(peak.peak_local_max(image, min_distance=5), + [[5, 5, 5, 5], [15, 15, 15, 15]]) + + if __name__ == '__main__': from numpy import testing testing.run_module_suite()