Repository navigation
Conversation
It seems that `peak_local_max` is almost identical to the deprecated function. The only difference I can find is the way the comparison with `min_distance` works. `corner_peaks` uses `>= min_distance` (equal or greater than), `peak_local_max` uses `> min_distance` (greater than). The way I see it, this behavior can be emulated by `peak_local_max`, by adding a small value (or `np.finfo(float).eps` to be exact) to `min_distance`. `corner_peaks` also has the additional parameter `indices` which I would have suggested to deprecate anyway. We want to avoid parameter flags that change the type of a functions output.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
doc/examples/transform/plot_matching.py (1)
59-64: Inconsistent epsilon strategy across the codebase.In
src/skimage/feature/orb.pyandtests/skimage/feature/test_corner.py, the pattern ismin_distance=N + np.finfo(float).eps, but here a hardcoded5.1is used. While functionally fine for this example, using0.1instead of machine epsilon could suppress peaks at distances in(5, 5.1]that the originalcorner_peaks(min_distance=5)would have kept.Consider using the same
epspattern for consistency and correctness, or at least a comment explaining the choice.tests/skimage/feature/test_match.py (1)
42-50: Inconsistent with other test files: usenp.finfo(float).epsinstead of hardcoded5.1.
test_corner.pyconsistently usesmin_distance=N + np.finfo(float).epsto replicatecorner_peaks's>=behavior, but here5.1is used. While0.1is large enough to work, it's semantically different — it could exclude peaks at distances in(5, 5.1]thatcorner_peaks(min_distance=5)would have kept.♻️ Align with the eps pattern used elsewhere
+ eps = np.finfo(float).eps keypoints1 = peak_local_max( - corner_harris(img), min_distance=5.1, threshold_abs=0, threshold_rel=0.1 + corner_harris(img), min_distance=5 + eps, threshold_abs=0, threshold_rel=0.1 ) ... keypoints2 = peak_local_max( - corner_harris(rotated_img), min_distance=5.1, threshold_abs=0, threshold_rel=0.1 + corner_harris(rotated_img), min_distance=5 + eps, threshold_abs=0, threshold_rel=0.1 )
|
@lagru I think we were not quite on the same page: I was saying to remove the function from skimage2. I don't see much harm in leaving it skimage1, and this will cause a lot of churn for not a lot of value? |
|
@jni Oh, I could live with that too. But we originally said that we would try to use conventional deprecations where ever we could... In any case, not too much work is wasted since the migration advice is still useful for |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/skimage/feature/orb.py (1)
149-153:⚠️ Potential issue | 🟡 MinorBehavioral change:
peak_local_maxdoes not suppress connected equal-value peaks.
corner_peaksapplied additional KDTree-based suppression of connected peaks with equal accumulator values on top ofpeak_local_max. The replacementpeak_local_maxalone may return more keypoints when adjacent FAST response pixels share the same value. In ORB this is likely benign since keypoints are later ranked by Harris response and capped ton_keypoints, but it is a subtle behavioral difference worth being aware of.
|
In my opinion, the goal of that advice is to not have skimage2 and skimage1 APIs be wildly different, which would complicate migration. But we must also balance that with not making skimage1 users do too much unnecessary work. I think keeping old functions around is not a burden. I suggest that we keep all the documentation changes and migration advice from this PR, but don't add a deprecation warning to the function — that function will just be there for backwards compatibility. Oh and the function docstring could have a note/warning — "prefer peak_local_max". |
mkcor
left a comment
There was a problem hiding this comment.
Before I continue reviewing, I'll wait for the decision on @jni's suggestion:
I suggest that we keep all the documentation changes and migration advice from this PR, but don't add a deprecation warning to the function — that function will just be there for backwards compatibility. Oh and the function docstring could have a note/warning — "prefer peak_local_max".
Personally, I'm 0+ on this.
@lagru I must have missed something because I'm not following this:
The only difference I can find is the way the comparison with
min_distanceworks.corner_peaksuses>= min_distance(equal or greater than),peak_local_maxuses> min_distance(greater than).
From the current (main) version of the code for corner_peaks,
https://github.com/scikit-image/scikit-image/blob/b235935d70c4803b93df510da1399dc9c74ff1c8/src/skimage/feature/corner.py#L1210C6-L1210C7,
it looks like min_distance is being used in the same way... The rest of the code seems to be rejecting (potentially) some peaks, so I don't see how corner_peaks can be less strict than peak_local_max.
Co-authored-by: Marianne Corvellec <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/skimage/_shared/utils.py (1)
719-725:is Truevs truthy check was already discussed in a prior review.The conditional logic is correct — when
prepend_docstringis falsy the original docstring is preserved while the runtimeFutureWarningstill fires as expected.
corner_peaks in favor of peak_local_maxcorner_peaks in favor of peak_local_max (skimage2 only)
While `corner_peaks` will only be removed in skimage2, it should follow the already introduced deprecations in `peak_local_max` related to passing `np.inf`.
corner_peaks in favor of peak_local_max (skimage2 only)corner_peaks with peak_local_max
|
Reviews (2): Last reviewed commit: "Address code review" | Re-trigger Greptile |
Conflicts: src/skimage/feature/corner.py tests/skimage/feature/test_brief.py tests/skimage/feature/test_corner.py tests/skimage/feature/test_match.py
|
Reviews (3): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile |
Conflicts: doc/source/user_guide/skimage2_migration.md src/skimage/feature/peak.py
|
Reviews (4): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile |
|
Reviews (5): Last reviewed commit: "Use migration decorator" | Re-trigger Greptile |
| - - ``exclude_border=False`` | ||
| - Use ``min_distance=0``. |
There was a problem hiding this comment.
The migration table entry for
exclude_border=False tells users to set min_distance=0, but the correct skimage2 equivalent is exclude_border=0. The warning section a few lines above this table correctly says exclude_border=0. Using min_distance=0 would silently disable all distance-based peak suppression rather than just lifting the border exclusion, giving users incorrect migration advice.
| - - ``exclude_border=False`` | |
| - Use ``min_distance=0``. | |
| - - ``exclude_border=False`` | |
| - Use ``exclude_border=0``. |
| >>> res1 = ski1.feature.corner_peaks(image, min_distance=10, indices=False) | ||
| >>> coords2 = ski2.feature.peak_local_max( | ||
| ... image, | ||
| ... min_distance=np.nextafter(10, np.inf), | ||
| ... exclude_border=10, | ||
| ... p_norm=np.inf | ||
| ... ) | ||
| >>> res2 = np.zeros_like(image, dtype=bool) | ||
| >>> res2[tuple(coords2.T)] = True | ||
| >>> np.testing.assert_equal(res1, res2) |
There was a problem hiding this comment.
I can't get this example to pass. I tried it with this reduced example:
Reduced example
import numpy as np
import skimage as ski1
import skimage2 as ski2
import matplotlib.pyplot as plt
image = ski1.data.camera()[:80, :80]
res1 = ski1.feature.corner_peaks(
image, min_distance=10, exclude_border=False, indices=False)
coo2 = ski2.feature.peak_local_max(
image, min_distance=np.nextafter(10, np.inf), exclude_border=False, p_norm=np.inf
)
res2 = np.zeros_like(image, bool)
res2[tuple(coo2.T)] = True
fig, ax = plt.subplots(1, 4, sharex=True, sharey=True)
ax[0].imshow(res1)
ax[1].imshow(res2)
ax[2].imshow(res1 ^ res2)
ax[3].imshow(image)
plt.show()
np.testing.assert_equal(res1, res2)I'm not sure how to verify this, but my hunch is that the we won't be able to achieve full backwards-compatibility. I think that is because internally the distance requirement is enforced in multiple phases: batched in _batched_ensure_spacing and then again in corner_peaks which does it's own KDTree-based filtering. Simply increasing min_distance with np.nexafter may not work, because of the "nonlinear" nature of these phases...
| else: | ||
| coordinates = np.empty((0, image.ndim), dtype=int) | ||
|
|
||
| if num_peaks is not None and len(coordinates) > num_peaks: |
There was a problem hiding this comment.
Another thing to check and consider:
- Check if peaks are always returned in intensity order
- If not, consider introducing that behavior in skimage2.
See also this thread: #8167 (comment)
Conflicts: src/skimage/feature/corner.py src/skimage/feature/orb.py tests/skimage/feature/test_corner.py
|
Reviews (6): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile |
|
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. |
|
Superseded by #8248. |
Description
It seems that
peak_local_maxis almost identical to the deprecated function. The only difference I can find is the way the comparison withmin_distanceworks.corner_peaksuses>= min_distance(equal or greater than),peak_local_maxuses> min_distance(greater than).The way I see it, this behavior can be emulated by
peak_local_max, by adding a small value (ornp.finfo(float).epsto be exact) tomin_distance.corner_peaksalso has the additional parameterindiceswhich I would have suggested to deprecate anyway. We want to avoid parameter flags that change the type of a functions output.Here's a reproducing example taken from Zulip #development > corner_peaks vs peak_local_max:
Details
Checklist
./doc/examplesfor new featuresRelease note
For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.