Repository navigation
Feature/sort peak local max - #8168
michaelbratsch wants to merge 10 commits into
Conversation
|
Reviews (1): Last reviewed commit: "Add unit test for sorted intensities" | Re-trigger Greptile |
| if len(coordinates): | ||
| # Globally sort by descending intensity so the labels path | ||
| # returns peaks in the same order as the labels=None path. | ||
| intensities = image[tuple(coordinates.T)] | ||
| coordinates = _filter_peaks( | ||
| coordinates, intensities, num_peaks, min_distance, p_norm | ||
| ) |
There was a problem hiding this comment.
Global spacing enforcement across labels is a breaking behavior change
The new code unconditionally calls _filter_peaks (which runs _ensure_spacing) whenever len(coordinates) > 0 and min_distance > 1. The old code only applied global spacing when num_peaks was set and the count exceeded it. This means peaks from adjacent labels that are within min_distance of each other can now be silently dropped even when num_peaks is None, which was not the case before. A caller using labeled regions (e.g., individual cells) with min_distance=5 would previously keep one peak per label regardless of inter-label distance; now the globally-highest-intensity label's peak can suppress a neighboring label's peak.
There was a problem hiding this comment.
I will look into this.
There was a problem hiding this comment.
The old code only applied global spacing when num_peaks was set and the count exceeded it
To me it seems that this is rather incoherent behaviour which is also not documented. I would assume that if one specifies labels then one wants the spacing applied for each label and not overall just because the num_peaks was exceeded.
I implemented it such that the output is sorted by intensity and output at most num_peaks if set. This means min_distance now has a strictly per-label scope when labels is set.
Needs to be discussed as this is a functional change!
There was a problem hiding this comment.
Giving you a bit of time to look into this before reviewing. Feel free to ping me once resolved!
There was a problem hiding this comment.
It has been discussed in the community meeting to only enforce the spacing for each label separately. I also updated the doc string accordingly and added a unit test.
@lagru From my side this PR looks good to me.
There has also been the discussion to remove the labels parameter from the peak_local_max function and put that functionality in some wrapper function. I think this should happen in a separate PR on top.
|
Reviews (2): Last reviewed commit: "Do not enforce min_distance when labels ..." | Re-trigger Greptile |
b37ce71 to
3e44547
Compare
|
Reviews (3): Last reviewed commit: "Remove skimage 2 test dependency on skim..." | Re-trigger Greptile |
NumPy lightly recommends using `assert_equal` for new code [1]. Other changes are just cosmetics for readability. [1] https://numpy.org/devdocs/reference/generated/numpy.testing.assert_array_equal.html#:~:text=consider%20using%20only%20assert_equal
|
Reviews (4): Last reviewed commit: "Tweak cosmetics and use `assert_equal`" | Re-trigger Greptile |
| if len(cand): | ||
| diff = coord_batch[cand] - coord_batch[idx] | ||
| dist = np.linalg.norm(diff, ord=p_norm, axis=1) | ||
| rejected[cand[dist < spacing]] = True |
There was a problem hiding this comment.
Is this strictly a performance optimization or is this necessary to preserve the ordering by intensity?
There was a problem hiding this comment.
This change is not necessary to preserve the ordering by intensity. So I do not mind if we kick it out of the pull request.
I did a small performance check on data.human_mitosis() and it performs good if there are many neighbours. Otherwise the KD-tree query will dominate.
| min_distance | old (ms) | new (ms) | speedup | #peaks |
|---|---|---|---|---|
| 1 | 5.50 | 5.47 | 1.00x | 65797 |
| 2 | 1066.46 | 790.95 | 1.35x | 18376 |
| 3 | 348.85 | 228.83 | 1.52x | 7744 |
| 5 | 81.94 | 60.17 | 1.36x | 2684 |
| 10 | 23.42 | 17.60 | 1.33x | 670 |
| 20 | 6.55 | 6.20 | 1.06x | 173 |
| 50 | 4.46 | 4.42 | 1.01x | 21 |
|
Thanks for the PR, @michaelbratsch! Could you update the PR description to outline the motivation for this change? |
|
(Looks like it simply is: this is what we promise to do in the docs. Why; is it useful to have them sorted? If so, looks like an innocuous change.) |
I updated the PR description so that it's easier to follow what has been modified and why it was done. |
|
Reviews (5): Last reviewed commit: "Add test to respect labels and not do gl..." | Re-trigger Greptile |
|
The PR can't be merged due to some merge conflict. Normally I would rebase the branch on main because that seems the cleanest to me. @lagru If I remember correctly, you rather prefer me to merge the main branch into the feature branch so that the review is easier. Is this true? |
|
We have changed the base branch for this PR from the Summary - what this means for your PRYou can continue to work on your PR, now based on Once we've merged your PR into the In addition - our automated script detected that your branch had merge conflicts with the pre-Megamove branch. Please make sure to merge in the Read on for the Megamove rationale, and more detailed instructions. DetailsRationaleWe've changed the base branch to make it easier and smoother to continue to work on your PR, while we work through a rather large change in the directory structure of the repository - a change that we have called Megamove. See the Megamove explanation issue for more detail. Changing the base branch means you do not see merge conflicts related to the Megamove change, and can continue to work with the repository in its original state, without worrying about porting those changes across to the new post-Megamove structure. As you'll see in the linked issue, you can continue to work on your PR as before, and you can continue to use the Github GUI to "Update branch" - this updates from the new To emphasize again, do not try and merge the scikit-image When we've approved your PR, we'll merge into the Any questions, please reply here. |
The merge request does the following:
peak_local_maxby descending peak intensity when providing labelscorner_peaksto return thenum_peaksin intensity order when using labels corner_peaks does not return the num_peaks in Intensity order when using labels #8143peak_local_maxis now always sorted (has already been sorted before when running without labels)num_peaks_batched_ensure_spacingRelates to: #8167
Relates to: #8057
Fixes: #8143
Release note (optional)