8000 Fix peak finding for empty images when indices=True · ttung/scikit-image@fee6d14 · GitHub
[go: up one dir, main page]

Skip to content

Commit fee6d14

Browse files
author
Tony Tung
committed
Fix peak finding for empty images when indices=True
scikit-image#3984 adds an optimization where a flat image immediately returns. However, it returns an array where the shape is incorrectly set to always be 2D when indices=True. A test is added to catch this scenario, and a fix is introduced where we set the output array's shape based on the input array's shape.
1 parent 5cb1b34 commit fee6d14

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

skimage/feature/peak.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def peak_local_max(image, min_distance=1, threshold_abs=None,
165165
# no peak for a trivial image
166166
if np.all(image == image.flat[0]):
167167
if indices is True:
168-
return np.empty((0, 2), np.int)
168+
return np.empty((0, image.ndim), np.int)
169169
else:
170170
return out
171171

skimage/feature/tests/test_peak.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ def test_empty(self):
228228
indices=False, exclude_border=False)
229229
assert np.all(~ result)
230230

231+
def test_empty_non2d_indices(self):
232+
image = np.zeros((10, 10, 10))
233+
result = peak.peak_local_max(image,
234+
footprint=np.ones((3, 3), bool),
235+
min_distance=1, threshold_rel=0,
236+
indices=True, exclude_border=False)
237+
assert result.shape[0] == 0
238+
assert result.shape[1] == image.ndim
239+
231240
def test_one_point(self):
232241
image = np.zeros((10, 20))
233242
labels = np.zeros((10, 20), int)

0 commit comments

Comments
 (0)
0