Skip to content

Align corner_peaks with peak_local_max - #8057

Closed
lagru wants to merge 42 commits into
scikit-image:pre-megamove-integrationfrom
lagru:depr-corner-peaks
Closed

lagru wants to merge 42 commits into
scikit-image:pre-megamove-integrationfrom
lagru:depr-corner-peaks

Conversation

@lagru

@lagru lagru commented Feb 17, 2026 •

Copy link
Copy Markdown
Member

Description

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.

Here's a reproducing example taken from Zulip #development > corner_peaks vs peak_local_max:

Details
import numpy as np
import skimage as ski

response = np.array(
    [[0, 0, 0, 0, 0],
     [0, 1, 1, 1, 0],
     [0, 1, 1, 1, 0],
     [0, 1, 1, 1, 0],
     [0, 0, 0, 0, 0]]
)

corners = ski.feature.corner_peaks(
    response, exclude_border=False, min_distance=1
)
peaks = ski.feature.peak_local_max(
    response, exclude_border=False, min_distance=1
)
diff = np.zeros_like(response)
diff[tuple(peaks.T)] = 1
diff[tuple(corners.T)] = 2
# array([[0, 0, 0, 0, 0],
#        [0, 2, 1, 2, 0],
#        [0, 1, 1, 1, 0],
#        [0, 2, 1, 2, 0],
#        [0, 0, 0, 0, 0]])

Checklist

Release note

For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.

Mark `skimage.feature.corner_peaks` as deprecated in favor of
`skimage2.feature.peak_local_max`. `corner_peaks` will stay
available in `skimage`.
{label="Maintenance"}
In `skimage.feature.corner_peaks`, support passing floats to the
parameter `min_distance`.
{label="Enhancement"}
In `skimage.feature.corner_peaks`, use `None` as the new default for the
parameters `num_peaks` and `num_peaks_per_label` – the default behavior is
the same as before but passing `numpy.inf` is deprecated.
{label="API"}
In `skimage.feature.corner_peaks`, ensure that the parameter `p_norm` is
forwarded to `peak_local_max` internally. Before, it was possible that
`peak_local_max` filtered too many peaks because.
{label="Bug fix"}

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.
@lagru lagru added 🔽 Deprecation Involves deprecation 📜 type: API Involves API change(s) labels Feb 17, 2026
@lagru
lagru marked this pull request as ready for review February 17, 2026 12:17
@coderabbitai

This comment was marked as outdated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py and tests/skimage/feature/test_corner.py, the pattern is min_distance=N + np.finfo(float).eps, but here a hardcoded 5.1 is used. While functionally fine for this example, using 0.1 instead of machine epsilon could suppress peaks at distances in (5, 5.1] that the original corner_peaks(min_distance=5) would have kept.

Consider using the same eps pattern 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: use np.finfo(float).eps instead of hardcoded 5.1.

test_corner.py consistently uses min_distance=N + np.finfo(float).eps to replicate corner_peaks's >= behavior, but here 5.1 is used. While 0.1 is large enough to work, it's semantically different — it could exclude peaks at distances in (5, 5.1] that corner_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
     )

Comment thread src/skimage/feature/corner.py Resolved
Comment thread tests/skimage/feature/test_corner.py Resolved
@jni

jni commented Feb 17, 2026

Copy link
Copy Markdown
Member

@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?

@lagru

lagru commented Feb 17, 2026

Copy link
Copy Markdown
Member Author

@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 skimage2.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment thread tests/skimage/feature/test_corner.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Behavioral change: peak_local_max does not suppress connected equal-value peaks.

corner_peaks applied additional KDTree-based suppression of connected peaks with equal accumulator values on top of peak_local_max. The replacement peak_local_max alone 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 to n_keypoints, but it is a subtle behavioral difference worth being aware of.

Comment thread tests/skimage/feature/test_corner.py Resolved
@jni

jni commented Feb 18, 2026

Copy link
Copy Markdown
Member

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 mkcor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_distance works. corner_peaks uses >= min_distance (equal or greater than), peak_local_max uses > 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.

Comment thread src/skimage/_shared/utils.py Resolved
Comment thread src/skimage/_shared/utils.py Resolved
Co-authored-by: Marianne Corvellec <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/skimage/_shared/utils.py (1)

719-725: is True vs truthy check was already discussed in a prior review.

The conditional logic is correct — when prepend_docstring is falsy the original docstring is preserved while the runtime FutureWarning still fires as expected.


ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c98f48 and d39abb3.

📒 Files selected for processing (1)
  • src/skimage/_shared/utils.py

Comment thread tests/skimage/feature/test_corner.py Resolved
@lagru
lagru marked this pull request as draft February 25, 2026 08:48
@lagru lagru changed the title Deprecate corner_peaks in favor of peak_local_max Deprecate corner_peaks in favor of peak_local_max (skimage2 only) Feb 25, 2026
@lagru lagru added the 🥾 Path to skimage2 A step towards the new "API 2.0" label Feb 25, 2026
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`.
@lagru lagru changed the title Deprecate corner_peaks in favor of peak_local_max (skimage2 only) Align corner_peaks with peak_local_max Feb 25, 2026
@lagru
lagru marked this pull request as ready for review February 25, 2026 16:25
@lagru lagru moved this from Doing to Review in Work pitches Mar 25, 2026
@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Address code review" | Re-trigger Greptile

Comment thread tests/skimage/feature/test_corner.py Resolved
@lagru lagru added 🔧 type: Maintenance Refactoring and maintenance of internals and removed 🔽 Deprecation Involves deprecation 📜 type: API Involves API change(s) labels Mar 25, 2026
Conflicts:
src/skimage/feature/corner.py
tests/skimage/feature/test_brief.py
tests/skimage/feature/test_corner.py
tests/skimage/feature/test_match.py
@greptile-apps

greptile-apps Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Reviews (3): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile

Comment thread src/skimage/feature/corner.py Resolved
Conflicts:
doc/source/user_guide/skimage2_migration.md
src/skimage/feature/peak.py
@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Reviews (4): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile

@lagru lagru moved this from Review to Doing in Work pitches Apr 29, 2026
@greptile-apps

greptile-apps Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Reviews (5): Last reviewed commit: "Use migration decorator" | Re-trigger Greptile

Comment thread src/skimage/feature/orb.py Resolved
Comment on lines +1179 to +1180
- - ``exclude_border=False``
- Use ``min_distance=0``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Suggested change
- - ``exclude_border=False``
- Use ``min_distance=0``.
- - ``exclude_border=False``
- Use ``exclude_border=0``.

Comment on lines +1218 to +1227
>>> 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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

@lagru lagru May 16, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@greptile-apps

greptile-apps Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Reviews (6): Last reviewed commit: "Merge branch 'main' into depr-corner-pea..." | Re-trigger Greptile

@matthew-brett
matthew-brett changed the base branch from main to pre-megamove-integration June 19, 2026 19:58
@matthew-brett

Copy link
Copy Markdown
Contributor

We have changed the base branch for this PR from the main branch to the pre-megamove-integration branch.

Summary - what this means for your PR

You can continue to work on your PR, now based on pre-megamove-integration. You should update your branch to the current state of pre-megamove-integration (this is what the Github "Update branch" button does). Please do not merge the scikit-image main branch into your PR branch.

Once we've merged your PR into the pre-megamove-integration branch, we'll update your changes for Megamove, and merge into the main branch.

In addition - our automated script detected that your branch had merge conflicts with the pre-Megamove branch. Please make sure to merge in the pre-megamove-integration branch, and resolve the merge conflicts in the way that you want.

Read on for the Megamove rationale, and more detailed instructions.

Details

Rationale

We'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 pre-megamove-integration branch. However, there is one caveat: please, do not try and merge the scikit-image main branch into this one, but instead, keep track of the pre-megamove-integration branch. The issue explains more.

To emphasize again, do not try and merge the scikit-image main branch. You will get Megamove related merge conflicts that are rather tricky to resolve correctly.

When we've approved your PR, we'll merge into the pre-megamove-integration branch, and then process it so we can merge it into the main branch. We'll let you know when we've merged your PR changes into main.

Any questions, please reply here.

@lagru

lagru commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Superseded by #8248.

@lagru lagru closed this Jul 8, 2026
@github-project-automation github-project-automation Bot moved this from Doing to Done in Work pitches Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🥾 Path to skimage2 A step towards the new "API 2.0" 🔧 type: Maintenance Refactoring and maintenance of internals

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants