Open vali19th opened 4 months ago
The same is true for morphology.opening
and morphology.binary_opening
.
It is an issue with the underlying scipy implementation see https://github.com/scipy/scipy/issues/13991
There are also similar discussions in https://github.com/scikit-image/scikit-image/issues/1190, for example: https://github.com/scikit-image/scikit-image/issues/1190#issuecomment-572384985
Maybe it makes sense to change the documentation and not confuse people that the binary operations are faster.
Rather bizarre!
The difference is even there for smaller kernels:
# 512x512
In [24]: %timeit ski.morphology.closing(bimage)
2.27 ms ± 24.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [25]: %timeit ski.morphology.binary_closing(bimage)
4.63 ms ± 30.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
Computed results are identical. The effect is also reproducible on larger images:
# 2048x2048
In [7]: %timeit ski.morphology.closing(bimage)
38.2 ms ± 783 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [8]: %timeit ski.morphology.binary_closing(bimage)
76 ms ± 2.75 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
I wonder if this is a regression in SciPy; it seems unlikely we would have written the guidance if it weren't true at the time. SciPy's docs state the same!
In terms of what to do, easiest for now may be to either (a) deprecate binary_dilation/closing
or to simply have those functions dispatch to dilation/closing
and remove the offending documentation.
I think the large kernel makes the timing differences more extreme
Agreed, dispatching in binary_dilation/closing to the faster functions seems like the way to go for now. As well as an update to the docstrings.
I agree that dispatching is possible but what is the point of keeping binary_dilation/closing
? It has fewer modes
than dilation/closing
and the original purpose was to have a faster interface for a specialised case which is not true anymore. So why bother dispatching and not go for deprecation? People can just use the other interface as a one-to-one replacement.
Maybe the functions can be marked as deprecated and changed to do the dispatching at the same time. This way, the library users will get the speedup without changing their code.
I tried the dispatching approach and then stumbled upon the same issues as being noted in https://github.com/scikit-image/scikit-image/issues/7238, dilation
and binary_dilation
have some inconsistencies in the way they operate, see
Padding of even-sized SEs
and
Mirroring of SE in dilation
That means that dispatching binary_dilation
to dilation
is not possible in a straight forward way. I would expect the same to be true for binary_erosion
. Spending much time to make it work does not seem appropriate to me because it is code we anyway want to get rid of.
I could provide a pull request to only mark the binary functions deprecated. Any thoughts on that?
Thanks @michaelbratsch, that sounds good to me.
:+1: on the deprecation approach. As long as we explain how to use alternatives properly with regards to mirroring and even-sized footprints. :) Feel welcome to request a review from me @michaelbratsch if you make a PR.
Description:
I tried with both of these images: 0_and_255.png 0_and_1.png
Docs saying it should be faster: https://scikit-image.org/docs/stable/api/skimage.morphology.html#skimage.morphology.binary_closing
Way to reproduce:
Version information: