morphology.label() bug?

Tony Yu tsyu80 at gmail.com
Wed Dec 21 15:36:45 EST 2011


On Sat, Dec 17, 2011 at 7:36 PM, karoyakani <tj.takei at gmail.com> wrote:

>
>
> On Dec 17, 3:27 am, Stéfan van der Walt <ste... at sun.ac.za> wrote:
> > On Sat, Dec 17, 2011 at 3:13 AM, Emmanuelle Gouillart
> >
> > <emmanuelle.gouill... at nsup.org> wrote:
> > >> > a = np.array([
> > >> >    [0,1,1,0,0,0],
> > >> >    [0,1,1,0,1,0],
> > >> >    [0,0,0,1,1,1],
> > >> >    [0,0,0,0,1,0]])
> >
> > >> This is the correct output, since the zero is not connected to any
> > >> other region.    In fact, ndimage labels it incorrectly as:
> >
> > >> array([[0, 1, 1, 0, 0, 0],
> > >>        [0, 1, 1, 0, 1, 0],
> > >>        [0, 0, 0, 1, 1, 1],
> > >>        [0, 0, 0, 0, 1, 0]])
> >
> > > Well, this is not incorrect, since ndimage.label only labels connected
> > > components of the foreground (True pixels).
> >
> > Right, so zero is a magical value.  I guess it's pretty easy to get
> > the same out of our implementation by simply masking out all
> > uninteresting values, and calling "unique" to get the remaining
> > labels?
>
> It's very useful and common that we assume Background:="0"-value
> pixels.
> ndimage and matlab do so.
> I don't know why skimage doesn't.
>
> Regarding connectedness, both matlab and ndimage have options of 8-
> connect and 4-connect.
> Meantime skimage has only 8-connect.
> Why don't we add 4-connect as an option?
>
> Regarding number of labeled regions (not counting the background
> regions), again matlab and ndimage compute and return it.
> Why don't we add it to the skimage, as it would be very useful to
> users?
>

Actually, I've always found the return values for `ndimage.label` to be
surprising. Every time I use it, I expect to just get the labeled array.
Isn't the number of labeled regions equal to the max value of the labeled
array?

-Tony


> I suspect the reason why the skimage doesn't is because it currently
> has a vague notion on the background regions, isn't it?
>
> Regards,
> TJ
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20111221/74bccd55/attachment.html>


More information about the scikit-image mailing list