Skip to content
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

implement binary structuring element decomposition #5388

Open
grlee77 opened this issue May 12, 2021 · 2 comments
Open

implement binary structuring element decomposition #5388

grlee77 opened this issue May 12, 2021 · 2 comments

Comments

@grlee77
Copy link
Contributor

grlee77 commented May 12, 2021

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 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 elements
y = img.copy()
for strel, iterations in structure_sequence:
    y = ndi.binary_dilation(y, strel, iterations=iterations)

whereas am proposing an API like the following:

structure_sequence = morphology.octagon(7, 4, as_sequence=True)
y = ndi.binary_dilation(x, structure_sequence)

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.

@rfezzani
Copy link
Member

Great suggestion @grlee77. It reminds me the getsequence function from Matlab/Octave.

@grlee77
Copy link
Contributor Author

grlee77 commented Jun 18, 2021

This is also related to #1070 and #1190

@scikit-image scikit-image locked and limited conversation to collaborators Oct 18, 2021
@grlee77 grlee77 reopened this Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants