Hello Johannes, thanks for the advise, but it did not work. When I set the background=0, the script counted one object when there were two. According to the one object coordinate, with centroid prop=(214.59826983468628, 505.59264087219293), it missed the small dot in the bottom of the image. Trying to understand what is the algorithm dose, I tested the following code: a=np.array(np.matrix('0 1 0 0 1;0 1 0 0 0; 0 0 0 0 0;0 0 0 0 1')) print(a) import numpy as np from skimage import filters, morphology, measure img=measure.label(a, background=0) propsa = measure.regionprops(img) length = len(propsa) print ('length='+str(length)) for label in propsa: print (label.centroid) returns 0 1 0 0 1] [0 1 0 0 0] [0 0 0 0 0] [0 0 0 0 1]] length=2 (0.0, 4.0) (3.0, 4.0) When trying a=np.array(np.matrix('0 1 0 0 1;0 1 0 0 0; 0 0 0 0 0;0 0 0 0 1')) print(a) import numpy as np from skimage import filters, morphology, measure img=measure.label(a) propsa = measure.regionprops(img) length = len(propsa) print ('length='+str(length)) for label in propsa: print (label.centroid) returns [[0 1 0 0 1] [0 1 0 0 0] [0 0 0 0 0] [0 0 0 0 1]] length=3 (0.5, 1.0) (0.0, 4.0) (3.0, 4.0) I do not understand why when background=0 the program counts two objects, and three object when background is default. Thanks for the help On Wednesday, November 18, 2015 at 7:34:30 PM UTC-9, Johannes Schönberger wrote:
Hi,
set background=0 when calling the label function.
Best, Johannes
On Nov 18, 2015, at 11:02 PM, Arctic_python <ejs...@alaska.edu <javascript:>> 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...@googlegroups.com <javascript:>. To post to this group, send email to scikit...@googlegroups.com <javascript:>. To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/18179150-16c2-4d34-b56f-8f3e6... <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. <4.png><4.csv><Auto Generated Inline Image 1.png>