// In the case of labels, recursively build and return an output
// operating on each label separately
if labels is not None:
labels_copy = labels.copy()label_values = np.unique(labels_copy)
// Reorder label values to have consecutive integers (no gaps)
if np.any(np.diff(label_values) != 1):
mask = labels_copy >= 1
labels_copy[mask] = 1 + rank_order(labels_copy[mask])[0].astype(labels_copy.dtype)
After Change
// operating on each label separately
if labels is not None:
labels = relabel_sequential(labels)[0]
for label in range(1, labels.max()+1):
maskim = labels == label
out += peak_local_max(image * maskim, min_distance=min_distance,
threshold_abs=threshold_abs,