Skip to content

Size of structuring elements a bit inconsistent #4536

Open

Description

@sciunto

Description

looking at the figure in #4528, it let me realize that the size of the structuring elements are a bit inconsistent, a fact I was not particularly aware of.

My use case is the following: while doing some processing, we might want to change the size and the shape of the structuring element. For instance, changing from square to circle, the user must be cautious to apply a factor two to get the same typical size.

Personally, I find this annoying.

Activity

  1. added this to the 1.0 milestone on Mar 30, 2020
  2. rfezzani commented on Mar 30, 2020

    @rfezzani
    Member

    I agree @sciunto, the inconsistency is even more visible looking at the API:

    • ball(radius)
    • cube(width)
    • diamond(radius)
    • disk(radius)
    • octagon(m, n)
    • octahedron(radius)
    • rectangle(width, height)
    • square(width)
    • star(a)

    I would harmonize the API using the radius argument name, since structuring elements are usually required to have even shapes...

  3. jni commented on Mar 30, 2020

    @jni
    Member

    Hi all!

    I don't think square(radius=5) makes much sense. People think of squares/rectangles as having a side length, and circular objects having a radius. How would one manage a rectangle with a radius anyway?

    Things like radius vs diameter are another story... We should pick one and stick to it. Given the side length argument for cubes, perhaps diameter is a better option. But, that is a lot of API churn for not a lot of gain. Perhaps something for the 1.0 transition? ;)

  4. rfezzani commented on Mar 30, 2020

    @rfezzani
    Member

    radius argument name must refer to the radius of the bounding box that encompass the desired structuring element. Using this definition, square(radius=5) doesn't bother me that much :-).

    Anisotropic shapes such as rectangle and octagon are however more touchy even if radii=(2, 3) is possible :-p

    This issue can be linked to #4154 and #4464 will help to deal with the API churn ;-)

  5. jni commented on Mar 30, 2020

    @jni
    Member

    @rfezzani

    Anisotropic shapes such as rectangle and octagon are however more touchy even if radii=(2, 3) is possible :-p

    Your face says it all. =P

    My personal preference is to use width/side length/diameter as the parameter. With radius, I am never sure if the centre pixel is included — does radius 1 correspond to a diameter of 3 or 2? We know 3 because we know it should be odd, but from a user perspective it's quite confusing really.

  6. sciunto commented on Mar 31, 2020

    @sciunto
    MemberAuthor

    My suggestion is to pass a size parameter for all, corresponding to the bbox:

    • circle(size) -> circle(3) [diameter]
    • rectangle(size) -> rectangle((3, 5)) [side length]
  7. rfezzani commented on Mar 31, 2020

    @rfezzani
    Member

    @jni

    We know 3 because we know it should be odd, but from a user perspective it's quite confusing really.

    Isn't education one of the goals of skimage?

    I personally didn't know what happens when selem shape is even, I had to dive in scipy code (which is used internally by skimage) to know what happens in this case: selem's center is shifted left... Not really obvious/intuitive...

  8. jni commented on Mar 31, 2020

    @jni
    Member

    Isn't education one of the goals of skimage?

    yep! We can educate by saying "diameter must be an odd number" in every docstring. =)

  9. rfezzani commented on Mar 31, 2020

    @rfezzani
    Member

    Well, radius makes the resulting shape odd by design... It is already used in four functions (ball, disk, diamond and octahedron) and see no user complaining or confused by its use...

    yep! We can educate by saying "diameter must be an odd number" in every docstring. =)

    Should we then check if diameter is odd at every function call? Should we warn or raise an error? In fact generating even shaped diamonds and disks will not be obvious...

    What about considering "anisotropic" selem (rectangle and octagon) particular cases?

  10. rfezzani commented on Apr 1, 2020

    @rfezzani
    Member

    @jni and @sciunto, I just checked and found that octagon produces square shaped selem. rectangle is then the only function that outputs non square structuring elements.

    We may then reasonably consider rectangle as a particular case.

    Now, decision have to be taken regarding the name of the parameter controlling the shape of the remaining selem functions to fix this issue and provide a consistent behavior for selem module's functions. We have two options:

    • size/diameter/width/side_length that describes the side length of the selem bbox with the necessity of taking care of even values (raising error?)
    • radius with the confusion that it may introduce in users mind concerning the output size (central pixel included or not)

    As you already noticed, may preference goes to the second option :-). May be other @scikit-image/core members can take part to the decision...

  11. jni commented on Apr 1, 2020

    @jni
    Member

    @rfezzani I found another argument against radius 😜: is the radius of a square the distance from the centre to the side, or to the corner?

  12. sciunto commented on Apr 1, 2020

    @sciunto
    MemberAuthor

    That's why I prefer a more generic word, for which the precise definition is provided in each docstring.

  13. rfezzani commented on Apr 1, 2020

    @rfezzani
    Member

    @rfezzani I found another argument against radius stuck_out_tongue_winking_eye: is the radius of a square the distance from the centre to the side, or to the corner?

    @jni, seriously? Did I ever said that a square has a radius, (even if it is sometimes True: the 2D ball with L_inf norm is a square)? I really don't understand why this hurts you that much...

    @sciunto, size is fine for me, just be aware that using this convention forces us to check for odd values, which I find unnecessary/inelegant...

  14. 16 remaining items

  15. rfezzani commented on Apr 2, 2020

    @rfezzani
    Member

    radius implies the thing fits into a sphere. That's not always the case for selems.

    Damn, only octagon doesn't always fit in a circle... 😄

  16. rfezzani commented on Apr 5, 2020

    @rfezzani
    Member

    The problem with the skimage current use of even selem shapes is that the behavior is not explicit and that the user have no control on it!
    I think that using the origin argument (as it is done in scipy.ndimage.morphology) addresses this problem.
    Even selem shapes are no more an issue at selem creation but at selem use. I mean that an error or a warning is only necessary if the selem shape is even and origin is 0...

    The use of size as generic argument has then no drawback apart the necessity for deprecation.

  17. sciunto commented on Jun 3, 2021

    @sciunto
    MemberAuthor

    Since there is deprecation going on for 0.20, perhaps we must consider this?

  18. rfezzani commented on Jun 7, 2021

    @rfezzani
    Member

    Thank you @sciunto. Is the proposed solution above (introducing the origin argument and using the size generic argument) OK for you?

  19. locked and limited conversation to collaborators on Oct 18, 2021
  20. unlocked this conversation on Mar 2, 2022
  21. reopened this on Mar 2, 2022
  22. modified the milestones: 1.0, skimage2 on Jun 28, 2022
  23. moved this to To Do in skimage2on Mar 1, 2025
  24. added
    🥾 Path to skimage2
    and removed on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔽 Deprecation🥾 Path to skimage2💬 Discussion

    Projects

    • Status
      To Do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions