-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
add iterations option to binary morphology operations #5387
base: main
Are you sure you want to change the base?
Conversation
replace use of numpy.testing and pytest calls with skimage._shared.testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @grlee77, great addition! We may be just need to choose the argument name iterations
in the light of #4154. num_iter
obtained some votes there.
BTW, I don't really like the aliases defined in skimage._shared.testing
for numpy.testing
and pytest
functions. These functions are somehow standard, using these aliases can confuse contributors. But this is a detail 🙂
I agree, but was thinking testing.parametrize was more commonly used here. A quick check reveals that this is mistaken, though:
so |
I am fine with using the |
Another motivation for adding this argument is my proposed structuring element decomposition feature (see #5388) |
minimize use of skimage._shared.testing for clarity
add num_iter to docstrings
@grlee77, I resolved the conflicts for this PR. Any update from your side? |
I think this issue is less high priority than I initially thought. I started this thinking I would use it to enable #5482, but I didn't end up needing it there (iterations are used, but only internally, not as a user-facing parameter). It may still be worth exposing the parameter to the end user, but then it does complicate things a little in the case of footprint sequences. One option would be to just multiply whatever iterations each sequence element already has by this "outer" number of iterations. What do you think? |
I think my preference would be to get #5482 merged first and then rebase this one afterwards. I can solicit a 2nd review in that PR. |
I agree, let's merge #5482 prior this PR and see then what is the best strategy to add the |
@@ -70,6 +73,9 @@ def binary_dilation(image, footprint=None, out=None): | |||
out : ndarray of bool, optional | |||
The array to store the result of the morphology. If None is | |||
passed, a new array will be allocated. | |||
num_iter : int | |||
The number of iterations to repeat binary_erosion with the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of iterations to repeat binary_erosion with the same | |
The number of iterations to repeat binary_dilation with the same |
@@ -106,21 +113,24 @@ def binary_opening(image, footprint=None, out=None): | |||
out : ndarray of bool, optional | |||
The array to store the result of the morphology. If None | |||
is passed, a new array will be allocated. | |||
num_iter : int | |||
The number of iterations to repeat binary_erosion with the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of iterations to repeat binary_erosion with the same | |
The number of iterations to repeat binary_opening with the same |
@@ -141,13 +151,16 @@ def binary_closing(image, footprint=None, out=None): | |||
out : ndarray of bool, optional | |||
The array to store the result of the morphology. If None, | |||
is passed, a new array will be allocated. | |||
num_iter : int | |||
The number of iterations to repeat binary_erosion with the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of iterations to repeat binary_erosion with the same | |
The number of iterations to repeat binary_closing with the same |
|
||
@pytest.mark.parametrize( | ||
"function", | ||
["binary_erosion", "binary_dilation", "binary_closing", "binary_closing"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["binary_erosion", "binary_dilation", "binary_closing", "binary_closing"] | |
["binary_erosion", "binary_dilation", "binary_opening", "binary_closing"] |
Description
Given that our binary morphology functions call the ones from SciPy, it would be useful to also expose arguments for
iterations
andorigin
. This PR adds aniterations
keyword argument which just gets passed along to the underlying SciPy functions.A motivating use case is to replace a single iteration of a large structuring element with multiple iterations of a smaller structuring element. For example
vs.
The iterated case takes 10.8 ms vs. 139 ms for the larger diamond on my system.
Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.