From d9e6b509c5c79ad2d85caf64049978fbf8d1762b Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 3 Apr 2013 17:56:04 +1100 Subject: [PATCH 1/2] Make `exclude_borders` option in peak_local_max nD Prior modifications to peak_local_max make it nd-aware, but this does not extend to the exclude_borders option. This commit changes that. --- skimage/feature/peak.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 1eadfc68..574d3e24 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -130,11 +130,12 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, image *= mask if exclude_border: - # Remove the image borders - image[:min_distance] = 0 - image[-min_distance:] = 0 - image[:, :min_distance] = 0 - image[:, -min_distance:] = 0 + # zero out the image borders + for i in xrange(image.ndim): + image = image.swapaxes(0, i) + image[:min_distance] = 0 + image[-min_distance:] = 0 + image = image.swapaxes(0, i) # find top peak candidates above a threshold peak_threshold = max(np.max(image.ravel()) * threshold_rel, threshold_abs) From 6e4ec78de2c44c9323aec39d58041166b1799d6c Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 3 Apr 2013 18:09:21 +1100 Subject: [PATCH 2/2] Use range instead of xrange --- skimage/feature/peak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/feature/peak.py b/skimage/feature/peak.py index 574d3e24..3268831a 100644 --- a/skimage/feature/peak.py +++ b/skimage/feature/peak.py @@ -131,7 +131,7 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, if exclude_border: # zero out the image borders - for i in xrange(image.ndim): + for i in range(image.ndim): image = image.swapaxes(0, i) image[:min_distance] = 0 image[-min_distance:] = 0