Discussion:
Problem with labeled.remove_regions_where()
jip
2014-04-28 16:47:29 UTC
Permalink
Hello,
I meet some problems with labeled.remove_regions_where(), with an error
message:

<Loading Image...>

mahotas.labeled.remove_regions: labeled is not as expected

The things work fine with a model example running in an ipython cell

import mahotas as mh
labarray = np.zeros((9,9), dtype=int16)
labarray[0:1,0:2] = 1
labarray[3:7,1:4] = 2
labarray[2:5,5:8] = 3
labarray, _ = mh.labeled.label(labarray)
labsiz = mh.labeled.labeled_size(labarray)
copy = mh.labeled.remove_regions_where(labarray, labsiz < 7)
mh.labeled.relabel(copy, inplace=True)

subplot(121)
title(labarray.dtype)
imshow(labarray, cmap=plt.cm.jet, interpolation='nearest')
subplot(122)
title(shape(copy))
imshow(copy, cmap=plt.cm.jet, interpolation='nearest')

The things goes wrong with this image obtained after watershed:


I checked its type, size, densitometric plot too:

<Loading Image...>

uint8 (38, 30) [ 0 0 0 0 0 0 25 25 25 25 32 32 0 0 0 0 30 30 0 0]


Now with the following code:

labsize2 = mh.labeled.labeled_size(chr_label)
ctd_elem = mh.labeled.remove_regions_where(chr_label, labsize2 < 4)
mh.labeled.relabel(ctd_elem, inplace=True)

there the following message:

--------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-7252923a5ad4> in <module>()
1 labsize2 = mh.labeled.labeled_size(chr_label)
----> 2 ctd_elem = mh.labeled.remove_regions_where(chr_label, labsize2 < 4)
3 mh.labeled.relabel(ctd_elem, inplace=True)

/usr/local/lib/python2.7/dist-packages/mahotas-1.1.0-py2.7-linux-i686.egg/mahotas/labeled.pyc in remove_regions_where(labeled, conditions, inplace)
208 '''
209 regions, = np.where(conditions)
--> 210 return remove_regions(labeled, regions, inplace=inplace)
211
212

/usr/local/lib/python2.7/dist-packages/mahotas-1.1.0-py2.7-linux-i686.egg/mahotas/labeled.pyc in remove_regions(labeled, regions, inplace)
176 your label image.
177 '''
--> 178 _check_array_labeled(labeled, labeled, 'remove_regions')
179 regions = np.asarray(regions, dtype=np.intc)
180 regions = np.unique(regions)

/usr/local/lib/python2.7/dist-packages/mahotas-1.1.0-py2.7-linux-i686.egg/mahotas/labeled.pyc in _check_array_labeled(array, labeled, funcname)
359 def _check_array_labeled(array, labeled, funcname):
360 if labeled.dtype != np.intc or not labeled.flags.carray:
--> 361 raise ValueError('mahotas.labeled.%s: labeled is not as expected' % funcname)
362 if array.shape != labeled.shape:
363 raise ValueError('mahotas.labeled.%s: `array` is not the same size as `labeled`' % funcname)

ValueError: mahotas.labeled.remove_regions: labeled is not as expected


Thank you for your advices.

Jean-Patrick
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2014-04-29 08:23:16 UTC
Permalink
Hi,

There are a few issues with the output of watershed and other labeled
functions (see, for example,
https://github.com/luispedro/mahotas/issues/41).

I actually plan to make this more flexible before releasing the next
version of mahotas.
labsize2 =mh.labeled.labeled_size(chr_label)
Add the following line:

chr_label = chr_label.astype(np.intc)
ctd_elem =mh.labeled.remove_regions_where(chr_label,labsize2 <4)
mh.labeled.relabel(ctd_elem,inplace=True)
HTH
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org

Recent stuff:
http://doi.org/10.1002/bies.201300143
http://dx.doi.org/10.1038/nm.3424
http://dx.doi.org/10.1038/nmeth.2693
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Jean-Patrick Pommier
2014-04-29 12:55:05 UTC
Permalink
There's no more interruption of execution. However, the lonely pixel is
not removed (whatever the threshold value, from 4 to 20 for ex, even if
bigger particles are removed). I can remove it on an image prior watershed.

jp
Post by Luis Pedro Coelho
Hi,
There are a few issues with the output of watershed and other labeled
functions (see, for example,
https://github.com/luispedro/mahotas/issues/41).
I actually plan to make this more flexible before releasing the next
version of mahotas.
labsize2 =mh.labeled.labeled_size(chr_label)
chr_label = chr_label.astype(np.intc)
ctd_elem =mh.labeled.remove_regions_where(chr_label,labsize2 <4)
mh.labeled.relabel(ctd_elem,inplace=True)
HTH
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org
http://doi.org/10.1002/bies.201300143
http://dx.doi.org/10.1038/nm.3424
http://dx.doi.org/10.1038/nmeth.2693
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2014-04-29 15:33:25 UTC
Permalink
Ah, that's actually the expected result for the image you had because
that pixel is not lonely :)

It belongs to region 209, which is a disconnected region[*].

imshow(chr_label == 209, interpolation='nearest')

HTH,
Luis

[*] Technically, disconnected only in traditional
4-connected/8-connected sense; if you have a large structuring element
defining neighbourhoods, it's connected.
Post by Jean-Patrick Pommier
There's no more interruption of execution. However, the lonely pixel is
not removed (whatever the threshold value, from 4 to 20 for ex, even if
bigger particles are removed). I can remove it on an image prior watershed.
jp
Hi,
There are a few issues with the output of watershed and other
labeled functions (see, for example,
https://github.com/luispedro/__mahotas/issues/41
<https://github.com/luispedro/mahotas/issues/41>).
I actually plan to make this more flexible before releasing the next
version of mahotas.
In the meanwhile, you can work around these limitations by
labsize2 =mh.labeled.labeled_size(chr___label)
chr_label = chr_label.astype(np.intc)
ctd_elem =mh.labeled.remove_regions___where(chr_label,labsize2 <4)
mh.labeled.relabel(ctd_elem,__inplace=True)
HTH
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org
http://doi.org/10.1002/bies.__201300143
<http://doi.org/10.1002/bies.201300143>
http://dx.doi.org/10.1038/nm.__3424 <http://dx.doi.org/10.1038/nm.3424>
http://dx.doi.org/10.1038/__nmeth.2693
<http://dx.doi.org/10.1038/nmeth.2693>
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it,
For more options, visit https://groups.google.com/d/__optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Jean-Patrick Pommier
2014-04-29 15:52:22 UTC
Permalink
I have to be careful to avoid this kind of pathologic situation.
Thanks a lot

jp
Ah, that's actually the expected result for the image you had because that
pixel is not lonely :)
It belongs to region 209, which is a disconnected region[*].
imshow(chr_label == 209, interpolation='nearest')
HTH,
Luis
[*] Technically, disconnected only in traditional 4-connected/8-connected
sense; if you have a large structuring element defining neighbourhoods,
it's connected.
Post by Jean-Patrick Pommier
There's no more interruption of execution. However, the lonely pixel is
not removed (whatever the threshold value, from 4 to 20 for ex, even if
bigger particles are removed). I can remove it on an image prior watershed.
jp
Hi,
There are a few issues with the output of watershed and other
labeled functions (see, for example,
https://github.com/luispedro/__mahotas/issues/41
<https://github.com/luispedro/mahotas/issues/41>).
I actually plan to make this more flexible before releasing the next
version of mahotas.
labsize2 =mh.labeled.labeled_size(chr___label)
chr_label = chr_label.astype(np.intc)
ctd_elem =mh.labeled.remove_regions___where(chr_label,labsize2 <4)
mh.labeled.relabel(ctd_elem,__inplace=True)
HTH
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org
http://doi.org/10.1002/bies.__201300143
<http://doi.org/10.1002/bies.201300143>
http://dx.doi.org/10.1038/nm.__3424 <http://dx.doi.org/10.1038/nm.
3424>
http://dx.doi.org/10.1038/__nmeth.2693
<http://dx.doi.org/10.1038/nmeth.2693>
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it,
For more options, visit https://groups.google.com/d/__optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...