Counting objects using label in skimage.measure

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


set background=0 when calling the label function.

Best, Johannes

> On Nov 18, 2015, at 11:02 PM, Arctic_python <ejsaiet at> 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 <mailto:scikit-image+unsubscribe at>.
> To post to this group, send email to scikit-image at <mailto:scikit-image at>.
> To view this discussion on the web, visit <>.
> For more options, visit <>.
> <4.png><4.csv><Auto Generated Inline Image 1.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the scikit-image mailing list