[ialabel] [Up] [iadither] Measurements

iarec
Reconstruction of a connect component.

Synopsis

g = iarec( f, seed )

Implemented in Python.

Input

f Image. Gray-scale (uint8 or uint16) or binary image (logical).

input image

seed Image. Gray-scale (uint8 or uint16) or binary image (logical).

seed coordinate

Output

g Image. Accepts any image data type.

Description

Extracts a connect component of an image by region growing from a seed.

Examples

>>> 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 = iarec(f, [0,3])

              
>>> print g
[[0 0 0 1 1]
 [0 0 0 1 0]]

Source Code

def iarec(f, seed):
    faux = 1*f
    g = 0*f
    S = [seed,]
    while len(S):
        P = S.pop()
        x, y = P[0], P[1]
        if 0 <= x < faux.shape[0] and 0 <= y < faux.shape[1]:
            if faux[x,y]:
                faux[x,y], g[x,y] = 0, 1
                S.append((x+1, y  ))
                S.append((x-1, y  ))
                S.append((x  , y+1))
                S.append((x  , y-1))
    return g
    
[ialabel] [Up] [iadither] http://www.python.org