[ialabel] [Up] [iadither] | Measurements |
Extracts a connect component of an image by region growing from a seed.
>>> 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]]
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] | |