[iacolorhist] [Up] [iarec] | Measurements |
Creates an image by labeling the connect components of the input binary image. The background pixels (with value 0) are not labeled. The maximum label value in the output image gives the number of its connected components.
>>> f = Numeric.array([[0,1,0,1,1], [1,0,0,1,0]])
>>> print f
[[0 1 0 1 1] [1 0 0 1 0]]
>>> g = ialabel(f)
>>> print g
[[0 1 0 2 2] [3 0 0 2 0]]
>>> f = iaread('blobs.pbm')
>>> g = ialabel(f);
>>> nblobs = max(Numeric.ravel(g))
>>> print nblobs
18
>>> iashow(f)
(128, 128) Min= 0 Max= 1 Mean=0.482 Std=0.50
>>> iashow(ialblshow(g))
(3, 128, 128) Min= 0.0 Max= 248.0 Mean=53.995 Std=72.93
f | ialblshow(g) |
def ialabel(f): from Numeric import zeros, nonzero, ravel faux = 1*f g = zeros(faux.shape) gaux = zeros(faux.shape) i = nonzero(ravel(faux)) k = 1 while len(i): aux = iaind2sub(faux.shape, i[0]) gaux = iarec(faux, (aux[0],aux[1])) faux = faux - gaux g = g + k*gaux k += 1 i = nonzero(ravel(faux)) return g
[iacolorhist] [Up] [iarec] | |