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

strel: more shape generators #75

Open
johnnychen94 opened this issue May 13, 2022 · 2 comments
Open

strel: more shape generators #75

johnnychen94 opened this issue May 13, 2022 · 2 comments
Milestone

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented May 13, 2022

Now we have strel_box and strel_window added in #65, the next step is to add a few more basic generators and (perhaps) a high-order generator. Just list a few ideas here:

Basic generators

  • strel_ball/strel_disk: generate a ball-shaped SE. There was a WIP in add connectivity generator helpers #63 for a generic ellipse shape
  • strel_line(sz, degree): generates a line segment along a certain degree
  • strel_octagon
  • strel_star

Unless we know there's room for optimization; we don't need to create new array types like strel_box or strel_diamond does. A plain function that generates plain OffsetArray{Bool} should be sufficient (don't forget that mask SE is centered to zero)

High-order compositor

If we have se1 of dimension N1 and se2 of dimension N2, it would be great to have a function strel_compose(se1, se2, ...) to build a N1+N2 dimension SE.

For instance, I would expect strel_compose(strel_line((3,)), strel_line((3,))) get us a strel_diamond((3, 3)). This might not need to be specific to strel, it can be generalized to a kernel composor since it can also useful for ImageFiltering.

This has two advantages:

  • makes building special SE more easily
  • permits room for optimization via the separable trick. For instance, extreme_filter for diamond SE is implemented this way.

To do the second, we need to build a new array type that is composed of two low-dimensional arrays. This tells Julia enough information to do dispatch.

@ThomasRetornaz I'm unsure which functions I listed above are useful in practice, and I'm not sure if I missed anything. It would be great if you can comment.

@ThomasRetornaz
Copy link
Collaborator

Sounds great

Few remarks:

  • strel_octagon could be obtain by composing unitary diamond and box SE
  • for a "linear" SE no problem if its fit nicely in the image domain grid (eg 0,90,145,45 degree) it will use default algorithme for "short" se, in case of "longer" se will use for instance van herck one or lemire or lemonier cf tab2 in https://hal-upec-upem.archives-ouvertes.fr/hal-00692897/document) . Pb arise whith other degree when we have to use breshenam to draw the se, in this cases 2D appraoch exist see https://www.cb.uu.se/~cris/Documents/Luengo2003c.pdf). In think we could wait to think about this second complicated case.
  • SE compositions or maybee more practical a tuple of SE could be useful.For instance huge rectangle is obtain by iterate two lines (horizontal vertical)
  • paper on SE decomposition exist see https://pure.rug.nl/ws/portalfiles/portal/2748142/2008IEEETIPUrbach.pdf. I think again we could wait for this. Because its not always trivial to determine if brute force algorithm is better than deomposition approach its depends on the shape :/.
    @johnnychen94

@johnnychen94
Copy link
Member Author

An update for this issue.

Now that we have strel_chain, we can simply build octagon shape SE with

function strel_octagon(m, n)
    diamonds = [strel_diamond((3, 3)) for _ in 1:m]
    boxes = [strel_box((3, 3)) for _ in 1:m-n]
    return strel_chain([diamonds..., boxes...])
end

julia> strel_octagon(3, 2)
7×7 ImageMorphology.StructuringElements.SEChainArray{2, OffsetArrays.OffsetMatrix{Bool, BitMatrix}} with indices -3:3×-3:3:
 0  0  1  1  1  0  0
 0  1  1  1  1  1  0
 1  1  1  1  1  1  1
 1  1  1  1  1  1  1
 1  1  1  1  1  1  1
 0  1  1  1  1  1  0
 0  0  1  1  1  0  0

What we need in the future are:

  • add strel_octagon function to the library and properly document it
  • strel_line for arbitrary degree: breshenam implementation. And optimized extreme_filter implementation for it.
  • optimized extreme_filter implementation for SEChainArray -- just iterate over the SE list

#90 (comment) seems to be a good candidate for arbitrary SE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants