| [mmgrain] [Up] [mmpatspec] | Measurements |
Implemented in Python.
| f | Image Gray-scale (uint8 or uint16) or binary image. |
| Bc | Structuring Element ( connectivity). Default:
|
| _lambda | Double Connectivity given by |f(q)-f(p)|<=_lambda. Default:
|
| y | Image If number of labels is less than 65535, the data type is uint16, otherwise it is int32. |
mmlabelflat creates the image
y by labeling the flat zones of
f, according to the connectivity defined by the structuring element
Bc. A flat zone is a connected region of the image domain in which all the pixels have the same gray-level (
lambda=0). When
lambda is different than zero, a quasi-flat zone is detected where two neighboring pixels belong to the same region if their difference gray-levels is smaller or equal
lambda. The minimum label of the output image is 1 and the maximum is the number of flat-zones in the image.
>>> f=uint8([ [5,5,8,3,0], [5,8,8,0,2]])
>>> g=mmlabelflat(f)
>>> print g
[[1 1 2 3 4] [1 2 2 5 6]]
>>> g1=mmlabelflat(f,mmsecross(),2)
>>> print g1
[[1 1 2 3 4] [1 2 2 4 4]]
>>> f=mmreadgray('blob.tif')
>>> d=mmdist(f,mmsebox(),'euclidean')
>>> g= d /8
>>> mmshow(g)
Warning: Converting input image from int32 to uint16.
>>> fz=mmlabelflat(g,mmsebox());
Warning: Converting input image from int32 to uint16.
>>> mmlblshow(fz)
>>> print mmstats(fz,'max')
13.0
![]() |
![]() |
|
| g | fz |
mmsebox) and if their gray-values difference is smaller or equal 3.
def mmlabelflat(f, Bc=None, _lambda=0):
from Numeric import allclose, ravel, nonzero, array
if Bc is None: Bc = mmsecross()
zero = mmbinary(mmsubm(f,f)) # zero image
faux = mmneg(zero)
r = array(zero)
label = 1
y = mmgray( zero,'uint16',0) # zero image (output)
while not allclose(faux,0):
x=nonzero(ravel(faux))[0] # get first unlabeled pixel
fmark = array(zero)
fmark.flat[x] = 1 # get the first unlabeled pixel
f2aux = mmcmp( f, '==', ravel(f)[x])
r = mminfrec( fmark, f2aux, Bc) # detects all pixels connected to it
faux = mmsubm( faux, r) # remove them from faux
r = mmgray( r,'uint16',label) # label them with the value label
y = mmunion( y, r) # merge them with the labeled image
label = label + 1
return y
| [mmgrain] [Up] [mmpatspec] | |
| Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |