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
Consider returning segments starting from 1 from SLIC #3722
We are getting close to being fully consistent in considering 0 to be the background in a label image. However, SLIC returns segments starting from 0, resulting in problems like this SO question:
where SLIC returns a full segmentation of the image, but segment 0 is ignored by regionprops. (Note: maybe the background segment should be measured by regionprops anyway!)
Hi @jni. I am a beginner and need some help undertanding the fix.
Like you suggested here, since we need to start from 1 instead of a 0, how about returning labels +1 as a temporary fix?
Firstly, there's probably a more efficient way of doing this within SLIC so that we don't have to duplicate a potentially huge labels array.
But, secondly, we have to worry about backwards compatibility, so the path to take is a bit tricky. We can't just change the output, but will have to instead add a flag to get the new behaviour, and a warning that the behaviour will change someday.
Can't we consider that the problem comes from regionprops and not from slic?
I mean that making regionpropos not consider 0 as background by default solves the problem.
So, adding an argument background to regionprops (like in the function skimage.measure.label) may do the trick.
@rfezzani well, that probably should happen anyway, yes (see #2755 and #3180), but I still think SLIC should return labels starting from 1, because it is a convention seen in many places, within the library (e.g. watershed returns labels from 1) but also in SciPy, which considers 0 as background for label and for find_objects (which is actually the source of this in regionprops).
Juan, I wonder if we should start a section in the user-guide for
"Commonly mentioned issues", and then discuss technical decisions like why we
label a certain way. This could also go in SKIPs, I guess, but maybe it
would be good to have this in a user-visible place for reference.
Activity
manasbedmutha98 commentedon Feb 5, 2019
Hi @jni. I am a beginner and need some help undertanding the fix.
Like you suggested here, since we need to start from 1 instead of a 0, how about returning
labels +1as a temporary fix?scikit-image/skimage/segmentation/slic_superpixels.py
Line 185 in a3d2557
Or else, any guidelines to go about?
jni commentedon Feb 5, 2019
@manasbedmutha98 thanks for chiming in!
Firstly, there's probably a more efficient way of doing this within SLIC so that we don't have to duplicate a potentially huge labels array.
But, secondly, we have to worry about backwards compatibility, so the path to take is a bit tricky. We can't just change the output, but will have to instead add a flag to get the new behaviour, and a warning that the behaviour will change someday.
rfezzani commentedon Apr 16, 2019
Can't we consider that the problem comes from
regionpropsand not fromslic?I mean that making
regionproposnot consider 0 as background by default solves the problem.So, adding an argument
backgroundtoregionprops(like in the functionskimage.measure.label) may do the trick.jni commentedon Apr 16, 2019
@rfezzani well, that probably should happen anyway, yes (see #2755 and #3180), but I still think SLIC should return labels starting from 1, because it is a convention seen in many places, within the library (e.g. watershed returns labels from 1) but also in SciPy, which considers 0 as background for
labeland forfind_objects(which is actually the source of this in regionprops).stefanv commentedon Apr 16, 2019
jni commentedon Apr 17, 2019
Yes, an FAQ is certainly needed. We should ensure we distinguish issues that are "settled" from those that we are actively exploring solutions to.