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
{{ message }}
Repository navigation
Size of structuring elements a bit inconsistent #4536
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.
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? ;)
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 ;-)
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.
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...
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?
@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...
@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...
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.
Activity
rfezzani commentedon Mar 30, 2020
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
radiusargument name, since structuring elements are usually required to have even shapes...jni commentedon Mar 30, 2020
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? ;)
rfezzani commentedon Mar 30, 2020
radiusargument 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
rectangleandoctagonare however more touchy even ifradii=(2, 3)is possible :-pThis issue can be linked to #4154 and #4464 will help to deal with the API churn ;-)
jni commentedon Mar 30, 2020
@rfezzani
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.sciunto commentedon Mar 31, 2020
My suggestion is to pass a size parameter for all, corresponding to the bbox:
rfezzani commentedon Mar 31, 2020
@jni
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...
jni commentedon Mar 31, 2020
yep! We can educate by saying "diameter must be an odd number" in every docstring. =)
rfezzani commentedon Mar 31, 2020
Well,
radiusmakes the resulting shape odd by design... It is already used in four functions (ball,disk,diamondandoctahedron) and see no user complaining or confused by its use...Should we then check if
diameteris 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 (
rectangleandoctagon) particular cases?rfezzani commentedon Apr 1, 2020
@jni and @sciunto, I just checked and found that
octagonproduces square shaped selem.rectangleis then the only function that outputs non square structuring elements.We may then reasonably consider
rectangleas 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
selemmodule's functions. We have two options:size/diameter/width/side_lengththat describes the side length of the selem bbox with the necessity of taking care of even values (raising error?)radiuswith 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...
jni commentedon Apr 1, 2020
@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?
sciunto commentedon Apr 1, 2020
That's why I prefer a more generic word, for which the precise definition is provided in each docstring.
rfezzani commentedon Apr 1, 2020
@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,
sizeis fine for me, just be aware that using this convention forces us to check for odd values, which I find unnecessary/inelegant...16 remaining items
rfezzani commentedon Apr 2, 2020
Damn, only
octagondoesn't always fit in a circle... 😄rfezzani commentedon Apr 5, 2020
The problem with the
skimagecurrent 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
originargument (as it is done inscipy.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
sizeas generic argument has then no drawback apart the necessity for deprecation.sciunto commentedon Jun 3, 2021
Since there is deprecation going on for 0.20, perhaps we must consider this?
rfezzani commentedon Jun 7, 2021
Thank you @sciunto. Is the proposed solution above (introducing the
originargument and using thesizegeneric argument) OK for you?