Bounding box on clusters in a 2D list

Lonnie Princehouse finite.automaton at gmail.com
Mon Apr 25 18:04:04 EDT 2005


def floodFill4(m, r, c, newCol, oldCol):
  stack = [ (r, c) ]
  while stack:
    r, c = stack.pop()
    if c >=0 and c < maxc and r >=0 and r< maxr and m[r][c]==oldCol:
      m[r][c] = newCol
      stack += [ (r+1, c), (r-1, c), (r, c+1), (r, c-1) ]




More information about the Python-list mailing list