Repository navigation
Conversation
This function can be made to return identical results to `ellipsis`, `disk` and `ball` in `skimage.morphology` if its input parameters are correctly configured. (Haven't tested yet if that is true for the `strict_radius=` parameter as well.) However, we probably don't want to keep parameters like `_legacy_sphere_compatible` around. But I'm uploading this prototype so we can discuss how we want to approach this API change between ski and ski2. Same is true for the `compare_func` parameter which may be overkill? But I think it is more elegant than a boolean flag.
|
Reviews (1): Last reviewed commit: "Add fully compatible `footprint_ellipsis..." | Re-trigger Greptile |
|
Reviews (2): Last reviewed commit: "Apply commit hooks" | Re-trigger Greptile |
| continue | ||
|
|
||
| # Create coordinate space along current dimension | ||
| radius = length // 2 # Integer division for legacy compatibility |
There was a problem hiding this comment.
This is another wart forced by the legacy implementation which also uses integer division.
I'd argue that float division would be more intuitive, since there is no reason to artificially shrink the radius by 0.5 here. This implementation has no trouble placing the edge of the ellipse exactly on the image border.
However, I saw no easy way to recover legacy results when using float division here. In theory using
adjust_radii = tuple(1 / (s // 2 * 2) + 1 for s in shape)should reproduce the results from _ellipse_in_shape but I think at larger radii it is running into float errors.
Not sure yet, if it's worth the same treatment as the other differences we allow ourselves with legacy ball and disk...
There was a problem hiding this comment.
I elected got keep using integer division here since that seems to align with what other libraries (Matlab, imagemagick) are doing.
Conflicts: src/skimage/morphology/footprints.py
|
Reviews (3): Last reviewed commit: "Merge branch 'main' into sk2-footprint-e..." | Re-trigger Greptile |
For consistency. Also, the function now always expects decomposed footprints; "flat" footprints raise an error.
This will be useful when making the cross-decomposition public.
I think this is more intuitive than specifying an offset to an implicit radius defined by `shape`.
|
Reviews (6): Last reviewed commit: "Avoid failure due to expected_warnings i..." | Re-trigger Greptile |
| * Instead of ``strict_radius=True`` (default), use ``adjust_edge=0.001`` | ||
| * Instead of ``strict_radius=False``, use ``adjust_edge=0.5`` |
There was a problem hiding this comment.
I'd like to get a second opinion here since this transition is the only time where we can freely chose this default.
The current default is adjust_edge=0.4 which I think leads to nicer looking footprints. I got the idea from imagemagick which recommends adding fractions between 0.3 and 0.5.
We could use adjust_edge=0.5 as the default, which would approximate the legacy behavior of strict_radius=False. But strict_radius=True is the default, so users need to adapt the signature in any case. What do you think?
There was a problem hiding this comment.
Using 0.4 is fine; we can advise the user on how to get 0.5 in the docs.
Between skimage and skimage2, we are removing disk/ball in favor of footprint_ellipse. So we need to duplicate docstring examples that make use of these APIs. This is too complex for `adapt_doctests`. So create thin wrappers in `skimage.filters.`, copy back the old docstrings.
and leave note about intentionally left implementation in there.
Conflicts: src/_skimage2/morphology/__init__.pyi src/_skimage2/morphology/footprints.py src/skimage/morphology/footprints.py tests/skimage2/morphology/test_footprints.py
|
Reviews (7): Last reviewed commit: "Merge branch 'main' into sk2-footprint-e..." | Re-trigger Greptile |
|
Reviews (8): Last reviewed commit: "Add migration wrapper for `footprint_fro..." | Re-trigger Greptile |
| qname_old="skimage.morphology.disk", | ||
| qname_new="skimage.morphology.footpint_ellipse", | ||
| ) | ||
| def disk(radius, dtype=np.uint8, *, strict_radius=True, decomposition=None): |
There was a problem hiding this comment.
Typo in
qname_new for disk's migration decorator — footpint_ellipse is missing the letter r. Every user who calls disk(...) will see the wrong function name in the deprecation warning, leading them to try to import footpint_ellipse and hit a ImportError.
| qname_old="skimage.morphology.disk", | |
| qname_new="skimage.morphology.footpint_ellipse", | |
| ) | |
| def disk(radius, dtype=np.uint8, *, strict_radius=True, decomposition=None): | |
| qname_old="skimage.morphology.disk", | |
| qname_new="skimage.morphology.footprint_ellipse", | |
| ) | |
| def disk(radius, dtype=np.uint8, *, strict_radius=True, decomposition=None): |
| from skimage._doctest_adapters import adapt_doctests | ||
|
|
||
| adapt_doctests(globals()) | ||
| def mean_bilateral( |
There was a problem hiding this comment.
Some other parts also seem like they may be unrelated.
|
Community call: drop shape, drop adjust_edge, recommend adjustment of radius in docs. EDIT: realized that this is a double operation: increase radius + crop footprint. So, we'll settle on a predictable outcome size: |
It's not necessary to keep old functionality and complicates the API and behavior significantly for something that's probably rarely used.
|
Reviews (9): Last reviewed commit: "Drop `shape` parameter from `footprint_e..." | Re-trigger Greptile |
| qname_old="skimage.morphology.ball", | ||
| qname_new="skimage.morphology.footpint_ellipse", | ||
| ) |
There was a problem hiding this comment.
The
ball migration decorator shares the same typo as disk — footpint_ellipse is missing the r. Every call to ball(...) will produce a deprecation warning pointing users to skimage.morphology.footpint_ellipse, which does not exist, causing them to hit an ImportError when following the migration guide.
| qname_old="skimage.morphology.ball", | |
| qname_new="skimage.morphology.footpint_ellipse", | |
| ) | |
| qname_old="skimage.morphology.ball", | |
| qname_new="skimage.morphology.footprint_ellipse", | |
| ) |
|
I dropped the
The current implementation explicitly doesn't allow passing floats to I'm happy to be convinced that the Right now it feels way cleaner to me: |
| # Intentionally left this old implementation in place so that | ||
| # compatibility tests comparing skimage and skimage2 behavior are | ||
| # meaningful |
|
|
||
| """ | ||
| if decomposition is None: | ||
| # Intentionally left this old implementation in place so that |
There was a problem hiding this comment.
I think it would be helpful to add here what to get rid of and when.
There was a problem hiding this comment.
Keep these as long as we keep the compatibility tests. Keep the tests, as long as we think we want to monitor the behavior of the ski2 algorithm to the legacy ones.
So I'd say, keep around until we remove the skimage namespace in question as part of the second phase.
| * Instead of ``strict_radius=True`` (default), use ``adjust_edge=0.001`` | ||
| * Instead of ``strict_radius=False``, use ``adjust_edge=0.5`` |
There was a problem hiding this comment.
Using 0.4 is fine; we can advise the user on how to get 0.5 in the docs.
| Parameters | ||
| ---------- | ||
| radius : int | ||
| The radius of the disk-shaped footprint. |
There was a problem hiding this comment.
OK with this being an int for now.
Is there any way for the user to get the behavior they would have gotten from radius=9.5 were floats allowed?
There was a problem hiding this comment.
Not sure I follow the question as you are commenting on the old skimage API?
The skimage1 code allows passing floats but this undocumented behavior isn't very straightforward: np.arange effectively computes the shape as ceil(radius) * 2 – which is of even size!
The new skimage2 API provides no way to support/reproduce that behavior since adjust_edge explicitly doesn't affect the shape.
If you want to support this, we'd need to add back (a) the optional shape parameter that I had proposed earlier, or (b), we allow floats for the radii parameter.
But (b) seems like a rather messy API with regards to how shape is computed.
Supersedes #7628.
In
skimage2: Replacesellipsis,diskandballwithfootprint_ellipse. The decomposition case is covered by the two new functionsfootprint_decomposed_diskandcross_decompose_footprint.In
skimage:ellipsis,diskandballare now thin wrappers around the skimage2 API. The migration process is documented with the usual decorator.(Kept up-to-date)
More details
The scope of this PR is to clean up our skimage2 API when it comes to functions that create elliptical footprints:
ellipsisdiskballin the
morphologymodule. In the process it would be very nice and elegant if a single n-dimensional algorithm could cover all these cases.However, the legacy implementation makes that difficult.
diskandballhave astrict_radiusparameter thatellipsisis lacking. Both groups also evaluate the ellipsis equation differently:ellipsisuses<, while the other functions use<=. But even worse, both groups solve this equation in a different associative form which leads to floating errors compounding differently.While getting to the root of this, I figured out a prototype
footprint_ellipsisfunction (6f2cb7b04), that can be made to return identical results to the legacy functions. However, we probably don't want to keep parameters like_legacy_sphere_compatiblearound. But I'm uploading this draft so we can discuss how we want to approach this API change between ski and ski2.Release note (optional)