# Copyright 2007 Regents of the University of California
# Written by David Isaacson at the University of California, Davis
# BSD License
def ExpandMask(input, iters):
"""
Expands the True area in an array 'input'.
Expansion occurs in the horizontal and vertical directions by one
cell, and is repeated 'iters' times.
"""
yLen,xLen = input.shape
output = input.copy()
for iter in xrange(iters):
for y in xrange(yLen):
for x in xrange(xLen):
if (y > 0 and input[y-1,x]) or \
(y < yLen - 1 and input[y+1,x]) or \
(x > 0 and input[y,x-1]) or \
(x < xLen - 1 and input[y,x+1]): output[y,x] = True
input = output.copy()
return output