Skip to content

Separate dense and decomposed footprint API#7746

Draft
lagru wants to merge 13 commits intoscikit-image:mainfrom
lagru:separate_footprint_decomposition
Draft

Separate dense and decomposed footprint API#7746
lagru wants to merge 13 commits intoscikit-image:mainfrom
lagru:separate_footprint_decomposition

Conversation

@lagru
Copy link
Copy Markdown
Member

@lagru lagru commented Mar 11, 2025

Description

Closes #7736; see that issue for more context. I'll expand this description as this PR shapes up.

  • Exposes _cross_decomposition as a new public footprint_cross_decompose.

Checklist

Release note

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

Add the new function `skimage.morphology.footprint_cross_decompose`, which can separate
symmetric convex 2-dimensional footprints into an equivalent series of smaller cross-shaped
footprints. {label="New feature"}
In `skimage.morphology.footprint_rectangle`, deprecate the argument `decomposition`;
instead use the new function `skimage.morphology.footprint_decomposed_rectangle` to 
create a series of footprints, that combine to an equivalent rectangular footprint. {label="API"}

@lagru lagru added 🔽 Deprecation Involves deprecation 📜 type: API Involves API change(s) 👶 type: New feature 🥾 Path to skimage2 A step towards the new "API 2.0" labels Mar 11, 2025
Since this function is now exposed to all kinds of footprints, I tried
to add sanity checks that didn't impact the performance to much and
tried to come up with a sensible behavior for edge cases.

It also removes the `dtype` parameter. Instead it just uses the dtype
of `footprint`, allowing users to control the outputs dtype that way.
I couldn't really think of use cases where the parameter would be
more useful.
@lagru lagru force-pushed the separate_footprint_decomposition branch from cd65537 to cc4fbab Compare March 13, 2025 15:57
lagru added 3 commits March 18, 2025 13:27
This should give users control on how correct the approximation is
supposed to be and also catches cases where the footprint isn't convex.
Comment on lines +714 to +718
for dim in range(footprint.ndim):
mirrored = np.flip(footprint, axis=dim)
if np.any(footprint != mirrored):
msg = f"`footprint` isn't symmetric in dimension {dim}"
raise ValueError(msg)
Copy link
Copy Markdown
Member Author

@lagru lagru Mar 18, 2025

Choose a reason for hiding this comment

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

With the addition of the max_error argument, this check isn't strictly necessary since an asymmetric footprint should usually exceed the allowed error rate. However, we may want to keep this because it provides a clearer warning?

Edit: not-convex -> asymmetric

Comment on lines +746 to +747
elif col_sums[i] < col_sums[i + 1]:
raise ValueError("`footprint` is not convex")
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.

Same here. This catches not-convex footprints but only in some cases and only in one dimension. E.g. it misses the holes in

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

So we could just remove this check.

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.

Note the function footprint_from_sequence(footprints) which is a bit of an outlier in terms of dtype behavior. Unlike all other footprint functions, it doesn't allow specifying the dtype and it returns a bool array by default; all others default to np.uint8.

If we want to change this default behavior, we'd have to do so in skimage2. Unless we rename the function to something like footprint_compose (which I prefer).

Thoughts?

@lagru lagru requested a review from stefanv March 18, 2025 13:55
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 7, 2026

Hello scikit-image core devs! There hasn't been any activity on this PR for more than 180 days. I have marked it as "dormant" to make it easy to find.

To our contributors, thank you for your contribution and apologies if this contribution fell through the cracks! Hopefully this ping will help bring some fresh attention to the review. If you need help, you can always reach out on our forum

If you think that this PR is no longer relevant, you may close it, or we may do it at some point (either way, it will be done manually). If you think the PR is valuable but you no longer have the bandwidth to update it, please let us know, so that someone can take it over. 🙏

@github-actions github-actions bot added the 😴 Dormant No recent activity label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔽 Deprecation Involves deprecation 🥾 Path to skimage2 A step towards the new "API 2.0" 📜 type: API Involves API change(s) 😴 Dormant No recent activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate decomposed footprint generation into extra functions

2 participants