Counting objects using label in skimage.measure

Arctic_python ejsaiet at alaska.edu
Wed Nov 18 23:02:52 EST 2015


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





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151118/35fa296a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 4.png
Type: image/png
Size: 3605 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151118/35fa296a/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 4.csv
Type: text/csv
Size: 853333 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151118/35fa296a/attachment.csv>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Auto Generated Inline Image 1
Type: image/png
Size: 10392 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151118/35fa296a/attachment-0001.png>


More information about the scikit-image mailing list