You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
corner_peaks does not return the num_peaks in Intensity order when using labels #8143
However, when you also supply labels, it appears that the order of returned peaks is actually first, in label ID order, then within a label, in descending intensity order. This can hide the strongest peaks, if they occur in later-numbered labels.
For example, if you have three labelled regions, with peak intensities of label0 : .1, 0.2; label1: 0.01; label3: 0.5.
calling peaks = skimage.feature.corner_peaks(match,num_peaks=2,labels=labels) would only return peaks from label0.
calling peaks = skimage.feature.corner_peaks(match,num_peaks=2,labels=labels,num_peaks_per_label=1) returns only label0 and label1 peaks.
Since I am trying to find the highest peak in each label, then filter down to only a few of the highest across the image, my work-around is
peaks=skimage.feature.corner_peaks(match,min_distance=5,num_peaks=np.max(labels),labels=labels,num_peaks_per_label=1) ##guarantees each label returns a single peakpeak_intensities= [match[peaks[i,0],peaks[i,1]] foriinrange(len(peaks))]
peaks=peaks[np.argsort(peak_intensities)[::-1],:]
peaks=peaks[:4,:] ## in this case, 4 would have been my original argument to num_peaks, if it worked the way I expected.
Way to reproduce:
importnumpyasnpimportskimageimg=np.zeros((6,6))
img[1,1] =1img[2,3] =2img[4,4] =3labels=skimage.measure.label(img>0)
peaks=skimage.feature.corner_peaks(img,num_peaks=2,labels=labels,num_peaks_per_label=1)
print(peaks) ##should be 4,4 then 2,3. instead gives 1,1 then 2,3
Version information:
3.13.12 (tags/v3.13.12:1cbe481, Feb 3 2026, 18:22:25) [MSC v.1944 64 bit (AMD64)]
Windows-11-10.0.26100-SP0
scikit-image version: 0.25.2
numpy version: 2.4.2
changed the title [-]peak_local_max does not return the num_peaks in Intensity order when using labels[/-][+]corner_peaks does not return the num_peaks in Intensity order when using labels[/+]on May 5, 2026
Activity
[-]peak_local_max does not return the num_peaks in Intensity order when using labels[/-][+]corner_peaks does not return the num_peaks in Intensity order when using labels[/+]michaelbratsch commentedon May 16, 2026
@ryandeon Thanks for taking the time to properly document the bug report and to come up with a small reproducer.
Sort corner_peaks when providing labels (#8167)