Skip to content

Port feature.canny to skimage2 - #8047

Merged
lagru merged 27 commits into
scikit-image:mainfrom
michaelbratsch:feature/move_canny_to_skimage2
Apr 21, 2026
Merged

lagru merged 27 commits into
scikit-image:mainfrom
michaelbratsch:feature/move_canny_to_skimage2

Conversation

@michaelbratsch

@michaelbratsch michaelbratsch commented Feb 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds the function canny to the skimage2 namespace. Compared to the old version in skimage it uses for the optional parameter mode the default nearest instead of constant.

See https://github.com/scikit-image/scikit-image/wiki/API-changes-for-skimage2#skimagefeature

Release note

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

Add `skimage2.feature.canny` which changes the default of the optional `mode` parameter from 
`constant` to `nearest` compared to the old version in `skimage.data`. The old version is now 
a simple wrapper around the implementation in `skimage2`.

@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: 4

🧹 Nitpick comments (2)
src/skimage2/feature/_canny.py (1)

8-13: Align import conventions (SciPy alias + relative shared utils).

Guidelines prefer import scipy as sp and relative imports under src/**. Here we use scipy.ndimage as ndi and absolute skimage.* imports. If skimage2 is meant to be self-contained, consider routing shared utilities via a skimage2._shared module and using relative imports; otherwise confirm this dependency is intentional.

♻️ Example adjustment for SciPy alias
-import scipy.ndimage as ndi
+import scipy as sp

As per coding guidelines: Use import conventions: import numpy as np, import matplotlib.pyplot as plt, import scipy as sp, import skimage as ski; and src/**/*.py: Use relative module imports (e.g., from .._shared import xyz rather than from skimage._shared import xyz).

tests/skimage2/feature/test_canny.py (1)

169-177: Consider adding explicit test for the new default mode='nearest' behavior.

The PR changes the default mode from "constant" to "nearest". While test_full_mask_matches_no_mask tests multiple modes explicitly, there's no test that verifies the default mode behavior has changed. Adding a test that confirms canny(image) uses mode='nearest' semantics (or comparing output against an explicit mode='nearest' call) would help document and protect this intentional API change.

Comment thread src/skimage2/feature/__init__.py Resolved
Comment thread src/_skimage2/feature/_canny.py Resolved
Comment thread src/_skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/meson.build 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

Comment thread src/skimage2/feature/_canny.py Resolved
@coderabbitai coderabbitai Bot added the 📜 type: API Involves API change(s) label Feb 1, 2026
@michaelbratsch
michaelbratsch force-pushed the feature/move_canny_to_skimage2 branch from 86da26c to a6f09e1 Compare February 1, 2026 17:45

@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

Comment thread src/skimage/feature/_canny.py Resolved
@michaelbratsch michaelbratsch changed the title Feature/move canny to skimage2 Port canny to skimage2 Feb 1, 2026
@michaelbratsch michaelbratsch changed the title Port canny to skimage2 Port feature.canny to skimage2 Feb 1, 2026
@lagru
lagru self-requested a review February 2, 2026 20:42
@lagru lagru added 🥾 Path to skimage2 A step towards the new "API 2.0" and removed 👶 type: New feature labels Feb 2, 2026

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

Thanks for tackling this!

Comment thread tests/skimage/feature/test_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved

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

We are updating the type descriptions to conform with docstub as we port to skimage2. The discussion regarding details is still ongoing but here and there we can already tweak things.

Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved

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

Looks really good from the get go. Nothing major outside the need to duplicate the test suite. Going by how the other PRs went, there'll be a bit of cleanup of the ported function in general after that. Shouldn't be too far off from getting this in.

@lagru lagru added this to skimage2 Feb 2, 2026
@github-project-automation github-project-automation Bot moved this to To Do in skimage2 Feb 2, 2026
@lagru lagru moved this from To Do to In progress in skimage2 Feb 2, 2026
@stefanv

stefanv commented Feb 2, 2026

Copy link
Copy Markdown
Member

@michaelbratsch Thanks so much for helping here; as you can see for the PRs, not many are brave enough to wade into these waters :)

Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/meson.build Resolved
Comment thread tests/skimage/feature/test_canny.py Resolved

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

Thank you so much for tackling this, @michaelbratsch!

Most comments / suggestions are not related to your contribution directly, but come from the 'old' canny and we are just seeing now some areas for improvement... We'll work through these with you! 🙏

Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.py Resolved
Comment thread src/skimage2/feature/_canny.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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
meson.build (1)

50-50: ⚠️ Potential issue | 🔴 Critical

Update line 50 to use the new path for the linker script.

The linker script file link-version-pyinit.map only exists at src/skimage2/_build_utils/, not at the old location. Line 50 still references src/skimage/_build_utils/link-version-pyinit.map and needs to be updated to src/skimage2/_build_utils/link-version-pyinit.map to be consistent with the path updates on lines 7, 61, and 62.

🧹 Nitpick comments (2)
src/meson.build (2)

82-82: Redundant cc redeclaration.

cc is already declared in the top-level meson.build (line 17) and should be visible in this subdir. This redeclaration is unnecessary.


118-140: cython_cpp_args is defined on line 123 then immediately overwritten on line 140 with unrelated content.

Line 123 defines cython_cpp_args as Cython CLI arguments (['@INPUT@', '@OUTPUT@', '--cplus']), but line 130 already inlines these args directly in the generator call, making line 123 dead code. Then line 140 reassigns cython_cpp_args to compiler warning flags (cython_c_args).

This works but the naming overlap is confusing. Consider removing the dead assignment on line 123, or renaming the compiler-args variable (e.g., cython_cpp_c_args) to distinguish it from the CLI args.

@michaelbratsch
michaelbratsch force-pushed the feature/move_canny_to_skimage2 branch 2 times, most recently from 1f7c5d5 to 19aa4a1 Compare February 7, 2026 09:35

@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

🧹 Nitpick comments (1)
src/skimage2/feature/_canny.py (1)

11-13: Cross-package imports from skimage internals into skimage2.

These absolute imports from skimage._shared and skimage.util are necessary since relative imports can't cross package boundaries. However, this couples skimage2 to skimage internal modules (_shared.filters, _shared.utils, util.dtype). As the migration to skimage2 progresses, consider whether these shared utilities should be lifted into a common internal package or duplicated into skimage2 to allow skimage to eventually become a thin wrapper without circular dependencies.

#!/bin/bash
# Check if skimage2 has its own _shared or util modules
fd -t f -p 'skimage2/_shared' -p 'skimage2/util'
echo "---"
# Check how other skimage2 modules handle imports from skimage
rg -n "from skimage\." --type=py -g 'src/skimage2/**'

Comment thread src/_skimage2/feature/_canny.py Resolved
@michaelbratsch
michaelbratsch force-pushed the feature/move_canny_to_skimage2 branch from c5e9d7f to 66c401a Compare February 7, 2026 09:43

@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 src/skimage/feature/_canny.py Resolved
@michaelbratsch
michaelbratsch force-pushed the feature/move_canny_to_skimage2 branch from 66c401a to de3b262 Compare February 7, 2026 09:46
@michaelbratsch

Copy link
Copy Markdown
Contributor Author

The only thing left is a nitpick asking for a test covering the new default behavior. Other than that, looks good.

Ahh right, that was a misunderstanding. I now added a unit test to check for the new default of the mode parameter.

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

Perfect. Ready to merge now and thank you for the work.

Conflicts:
src/_skimage2/feature/_canny.py
src/_skimage2/feature/_canny_cy.pyx
@lagru

lagru commented Mar 17, 2026

Copy link
Copy Markdown
Member

@michaelbratsch, note that #8093 recently moved all skimage2 implementations into _skimage2 (skimage2 is now only a thin wrapper with a warning). I resolved the merge conflicts for you since had some routine on doing so from my other PRs. 😉 Please pull to your local branch before you would push more changes.

@michaelbratsch

Copy link
Copy Markdown
Contributor Author

@michaelbratsch, note that #8093 recently moved all skimage2 implementations into _skimage2 (skimage2 is now only a thin wrapper with a warning). I resolved the merge conflicts for you since had some routine on doing so from my other PRs. 😉 Please pull to your local branch before you would push more changes.

Thank you for resolving the latest merge conflicts from master. From my side the pull request is complete. I guess now one more approval is missing for the merge.

I saw that one unit test for macOS python 3.13 is failing

FAILED tests/skimage/restoration/test_unwrap.py::test_wrap_around[3-2] - AssertionError: 
Arrays are not almost equal to 7 decimals
 ACTUAL: np.float64(-25.132741228718345)
 DESIRED: np.float64(12.566370614359172)

which I can't reproduce on my Mac M1. Is this test know to be unstable?

# Smooth out the masked image.
smoothed_image = gaussian(masked_image, **gaussian_kwargs)

# Lower the result by the bleed-over fraction, so you can

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.

Wish I knew what this meant :)

Comment thread src/_skimage2/feature/_canny.py Resolved
Comment thread src/_skimage2/feature/_canny.py Resolved
@stefanv stefanv moved this from Review to Doing in Work pitches Mar 19, 2026
@lagru

lagru commented Mar 19, 2026

Copy link
Copy Markdown
Member

which I can't reproduce on my Mac M1. Is this test [test_wrap_around] know to be unstable?

Yes, very much annoyingly so. See #7964 for the details. We temporarily marked it as an expected failure

@pytest.mark.xfail(
condition=sys.platform == "darwin" and date.today() < date(2026, 2, 1),
reason="Flakiness on macOS (gh-7964, xfail expires 2026-02-01)",
raises=AssertionError,
strict=False,
)

That has expired now. 💁

Co-authored-by: Stefan van der Walt <[email protected]>
@michaelbratsch

Copy link
Copy Markdown
Contributor Author

which I can't reproduce on my Mac M1. Is this test [test_wrap_around] know to be unstable?

Yes, very much annoyingly so. See #7964 for the details. We temporarily marked it as an expected failure

@pytest.mark.xfail(
condition=sys.platform == "darwin" and date.today() < date(2026, 2, 1),
reason="Flakiness on macOS (gh-7964, xfail expires 2026-02-01)",
raises=AssertionError,
strict=False,
)

That has expired now. 💁

Having an expected failure with a timeout is a funny concept but I get the point in wanting to come back to it later.

Maybe the flaky behaviour is fixed by https://github.com/scikit-image/scikit-image/pull/8099/changes

@lagru lagru moved this from Doing to Review in Work pitches Mar 24, 2026
@lagru
lagru self-requested a review April 20, 2026 17:09
Conflicts:
src/_skimage2/feature/_canny_cy.pyx
src/meson.build
src/skimage/feature/_canny.py
src/skimage/meson.build
@greptile-apps

greptile-apps Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Merge branch 'main' into 'move_canny_to_..." | Re-trigger Greptile

Comment thread src/_skimage2/feature/_canny.py Resolved
@greptile-apps

greptile-apps Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Note keyword-only change in message" | Re-trigger Greptile

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

I took the liberty to resolve the merge conflicts caused by _shared being moved to _skimage2.

We still need to port the existing tests in test_canny to skimage2. But I'll do a a quick follow-up PR for that.

I'll merge if the CI stays happy, because I am. Thank you @michaelbratsch!

@lagru lagru added 🔧 type: Maintenance Refactoring and maintenance of internals and removed 📜 type: API Involves API change(s) labels Apr 21, 2026
@lagru
lagru merged commit d00454c into scikit-image:main Apr 21, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from Review to Done in Work pitches Apr 21, 2026
@github-project-automation github-project-automation Bot moved this from To Review to Done in skimage2 Apr 21, 2026
@stefanv stefanv added this to the 0.27 milestone Apr 21, 2026
matthew-brett added a commit that referenced this pull request Apr 21, 2026
* origin/main:
  Port feature.canny to skimage2 (#8047)
  Revert "Add AI contribution policy (#7982)" (#8124)
  Add AI contribution policy (#7982)
matthew-brett added a commit to matthew-brett/scikit-image that referenced this pull request Apr 23, 2026
* origin/main:
  Drop 3.13t builds from cibuildwheel configuration (scikit-image#8127)
  Restore wording of AI policy (scikit-image#8123)
  Port feature.canny to skimage2 (scikit-image#8047)
  Revert "Add AI contribution policy (scikit-image#7982)" (scikit-image#8124)
  Add AI contribution policy (scikit-image#7982)
lagru added a commit that referenced this pull request Apr 26, 2026
Followup to #8047. This ports the full test suite
for features.canny to skimage2.
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
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants