-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Backport #3447: Fix morphology.local_maxima for input with any dimension < 3 #3545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…image#3447) * Fix local_maxima for input with dimensions < 3 local_maxima (and local_minima) failed with an ValueError for images with at least 1 dimension with fewer than 3 elements. This was due to the implementation which applies a structuring element with exactly 3 elements in each dimension to the image in question. This behavior was only visible if `allow_borders` was false, otherwise the image was padded internally. This fix makes these functions work for the mentioned edge cases by testing the image shape at the appropriate time. * Fix output of local_maxima for empty arrays The old output for empty arrays if `indices` was true didn't correspond to the output for non-empty arrays and the description in the docstring. This ensures that the output will always be a tuple of empty arrays. If `indices` is false, the returned empty array now machtes the shape of `image` as well. * Show warning if no maxima are possible which is the case for dimensions with fewer than 3 samples. Because `local_minima` wraps `local_maxima` the warning can only set the correct stacklevel for one of these functions. The latter was chosen because it stands to reason that it is / will be used more frequently. If may be possible to suppress and re-raise the warning with the context manager from the warnings module but that would introduce non-thread- safe code and introduce perhaps unnecessary complexity. * Point user to allow_borders in warning message
Hello @stefanv! Thanks for submitting the PR.
|
Did you miss some commits or did we forget to backport a prerequisite PR? These changes clearly don't make sense on their own. See: definition only has image and selem, but this PR appears to add many more. |
I guess there must be other PRs that were missed; I wasn't tracking. |
Yeah, you missed #3022 which introduces the rewrite of |
Ooops! I can see that we even tried the auto backport and then totally dropped the ball when it failed. Yes @lagru that's indeed what's required. Maybe you can pile these on as well onto the same PR? =) |
@jni Happy to do so. However maybe you can give me some tips so I do this the right way from the start: My first impulse is to cherry-pick the commits in these two PRs (sans merge commits?) onto a new branch (e.g. |
|
Thanks! Why didn't I think of that? 🙈 |
@lagru because git man-pages are appallingly bad. =D I highly recommend
Incidentally, it looks like my advice was slightly wrong... There should have been a |
@jni Yes, The PR has all commits except for the merge-commits.
Thank you! This is gold! |
local_maxima (and local_minima) failed with an ValueError for images
with at least 1 dimension with fewer than 3 elements. This was due to
the implementation which applies a structuring element with exactly 3
elements in each dimension to the image in question. This behavior was
only visible if
allow_borders
was false, otherwise the image waspadded internally.
This fix makes these functions work for the mentioned edge cases by
testing the image shape at the appropriate time.
The old output for empty arrays if
indices
was true didn't correspondto the output for non-empty arrays and the description in the docstring.
This ensures that the output will always be a tuple of empty arrays.
If
indices
is false, the returned empty array now machtes the shape ofimage
as well.which is the case for dimensions with fewer than 3 samples. Because
local_minima
wrapslocal_maxima
the warning can only set the correctstacklevel for one of these functions. The latter was chosen because it
stands to reason that it is / will be used more frequently.
If may be possible to suppress and re-raise the warning with the context
manager from the warnings module but that would introduce non-thread-
safe code and introduce perhaps unnecessary complexity.
Description
[Tell us about your new feature, improvement, or fix! If relevant, please supplement the PR with images.]
Checklist
[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
[For detailed information on these and other aspects see scikit-image contribution guidelines]
References
[If this is a bug-fix or enhancement, it closes issue # ]
[If this is a new feature, it implements the following paper: ]
For reviewers
(Don't remove the checklist below.)
later.
__init__.py
.doc/release/release_dev.rst
.@meeseeksdev backport to v0.14.x