You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As shown in #5387 and scipy/scipy#13991, it can be advantageous (order of magnitude acceleration!) to apply iterated small structuring elements instead of a large structuring element.
For the existing square, rectangle, cube, diamond, octahedron and octagon, there are simple decompositions that we could provide which would give a more efficient way to perform the same operation. I want to propose the following two ideas related to this:
1.) Add a keyword-only argument to this structuring element generators that would return a decomposition in terms of series of smaller elements. Something like as_series=False.
For example morphology.octagon(7, 4) is equivalent to the following sequence: ((np.ones((7, 1)), 1), (np.ones((1, 7)), 1), (morphology.diamond(1), 4))
Here the first element of each 2-tuple is a structuring element and the second element is how many iterations it should be applied.
2.) Add capability to the existing erosion, dilation, opening and closing functions to detect a "series of structures" input and apply the series of operations for the user.
Currently the user would have to determine a sequence on their own and then apply it using something like:
# define a sequence of structuring elements equivalent to morphology.octagon(7, 4)structure_sequence= ((np.ones((7, 1)), 1), (np.ones((1, 7)), 1), (morphology.diamond(1), 4))
# apply a sequence of structuring elementsy=img.copy()
forstrel, iterationsinstructure_sequence:
y=ndi.binary_dilation(y, strel, iterations=iterations)
I am only proposing to do this in these simple cases, where we can determine series elements analytically. There are more complicated general algorithms in the literature to determine an "optimum" decomposition into e.g. 3x3 elements for more general shapes, but those can be pretty complicated and which decomposition is truly "optimal" will likely depend on a specific hardware architecture.
The text was updated successfully, but these errors were encountered:
Description
As shown in #5387 and scipy/scipy#13991, it can be advantageous (order of magnitude acceleration!) to apply iterated small structuring elements instead of a large structuring element.
For the existing
square
,rectangle
,cube
,diamond
,octahedron
andoctagon
, there are simple decompositions that we could provide which would give a more efficient way to perform the same operation. I want to propose the following two ideas related to this:1.) Add a keyword-only argument to this structuring element generators that would return a decomposition in terms of series of smaller elements. Something like
as_series=False
.For example
morphology.octagon(7, 4)
is equivalent to the following sequence:((np.ones((7, 1)), 1), (np.ones((1, 7)), 1), (morphology.diamond(1), 4))
Here the first element of each 2-tuple is a structuring element and the second element is how many iterations it should be applied.
2.) Add capability to the existing
erosion
,dilation
,opening
andclosing
functions to detect a "series of structures" input and apply the series of operations for the user.Currently the user would have to determine a sequence on their own and then apply it using something like:
whereas am proposing an API like the following:
I am only proposing to do this in these simple cases, where we can determine series elements analytically. There are more complicated general algorithms in the literature to determine an "optimum" decomposition into e.g. 3x3 elements for more general shapes, but those can be pretty complicated and which decomposition is truly "optimal" will likely depend on a specific hardware architecture.
The text was updated successfully, but these errors were encountered: