Merge pull request #1355 from kevin-keraudren/peak_local_max-NDarrays-issue1354

ENH: Full ndarray support for peak_local_max
This commit is contained in:
Josh Warner
2015-01-24 18:17:28 -07:00
3 changed files with 15 additions and 3 deletions
+4 -1
View File
@@ -202,4 +202,7 @@
Extended the image labelling implementation so it also works on 3D images.
- Salvatore Scaramuzzino
RectTool example
RectTool example
- Kevin Keraudren
Fix and test for feature.peak_local_max
+2 -2
View File
@@ -146,10 +146,10 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1,
peak_threshold = max(np.max(image.ravel()) * threshold_rel, threshold_abs)
# get coordinates of peaks
coordinates = np.transpose((image > peak_threshold).nonzero())
coordinates = np.argwhere(image > peak_threshold)
if coordinates.shape[0] > num_peaks:
intensities = image[coordinates[:, 0], coordinates[:, 1]]
intensities = image.flat[np.ravel_multi_index(coordinates.transpose(),image.shape)]
idx_maxsort = np.argsort(intensities)[::-1]
coordinates = coordinates[idx_maxsort][:num_peaks]
+9
View File
@@ -82,6 +82,15 @@ def test_num_peaks():
assert (3, 5) in peaks_limited
def test_num_peaks3D():
# Issue 1354: the old code only hold for 2D arrays
# and this code would die with IndexError
image = np.zeros((10, 10, 100))
image[5,5,::5] = np.arange(20)
peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=2)
assert len(peaks_limited) == 2
def test_reorder_labels():
image = np.random.uniform(size=(40, 60))
i, j = np.mgrid[0:40, 0:60]