Counting objects using label in skimage.measure

Johannes Schönberger jsch at demuc.de
Wed Nov 18 23:34:26 EST 2015


Hi,

set background=0 when calling the label function.

Best, Johannes

> On Nov 18, 2015, at 11:02 PM, Arctic_python <ejsaiet at alaska.edu> wrote:
> 
> Hello,
> I am trying to count the number of objects(that has "ones") in a binary array. Of course I do not expect to count holes.
> But when I run the below code,
> file1='4.csv'
> a=np.loadtxt(open(file1,'rb'),delimiter=',',dtype=int)
> #print (a.shape)
> 
> img=measure.label(a)
> propsa = measure.regionprops(img)
> length = len(propsa)
> print ('length='+str(length))
> for label in propsa:
>     print (label.centroid)
> 
> returns
> 
> length=2
> (214.23444957510378, 505.25546156532539)
> (238.77173913043478, 740.28260869565213)
> I get two objects. From reading the centroid coordinates(above), it seems it is counting the center of the white object and the cavity (can be seen in the image bellow).  
> Why is this algorithm counting cavities and not only objects that are of "ones"? Is there an argument to enforce only objects and not cavities? 
> Attached is the csv file if you want to try for yourself.
> Thanks
> 
> 
> 
> 
> <Auto Generated Inline Image 1.png>
> 
> -- 
> You received this message because you are subscribed to the Google Groups "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe at googlegroups.com <mailto:scikit-image+unsubscribe at googlegroups.com>.
> To post to this group, send email to scikit-image at googlegroups.com <mailto:scikit-image at googlegroups.com>.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/18179150-16c2-4d34-b56f-8f3e6d91401f%40googlegroups.com <https://groups.google.com/d/msgid/scikit-image/18179150-16c2-4d34-b56f-8f3e6d91401f%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
> <4.png><4.csv><Auto Generated Inline Image 1.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151118/bc672841/attachment.html>


More information about the scikit-image mailing list