mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Merge pull request #906 from ahojnnes/peak-fix
`peak_local_max`: fix docstring, add N-d tests
This commit is contained in:
+13
-8
@@ -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
|
||||
|
||||
@@ -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,30 @@ 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]])
|
||||
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user