'**SUMMARY**
floodFillToMask works sorta paint bucket tool in your favorite image manipulation
program. You select a point (or a list of points), a color, and a tolerance, and floodFill will start at that
point, looking for pixels within the tolerance from your intial pixel. If the pixel is in
tolerance, we will convert it to your color, otherwise the method will leave the pixel alone.
Unlike regular floodFill, floodFillToMask, will return a binary mask of your flood fill
operation. This is handy if you want to extract blobs from an area, or create a
selection from a region. The method takes in an optional mask. Non-zero values of the mask
act to block the flood fill operations. This is handy if you want to use an edge image
to "stop" the flood fill operation within a particular region.
The method accepts both single values, and triplet tuples for the tolerance values. If you
require more control over your tolerance you can use the upper and lower values. The fixed
range parameter let\'s you toggle between setting the tolerance with repect to the seed pixel,
and using a tolerance that is relative to the adjacent pixels. If fixed_range is true the
method will set its tolerance with respect to the seed pixel, otherwise the tolerance will
be with repsect to adjacent pixels.
**PARAMETERS**
* *points* - A tuple, list of tuples, or np.array of seed points for flood fill
* *tolerance* - The color tolerance as a single value or a triplet.
* *color* - The color to replace the floodFill pixels with
* *lower* - If tolerance does not provide enough control you can optionally set the upper and lower values
around the seed pixel. This value can be a single value or a triplet. This will override
the tolerance variable.
* *upper* - If tolerance does not provide enough control you can optionally set the upper and lower values
around the seed pixel. This value can be a single value or a triplet. This will override
the tolerance variable.
* *fixed_range* - If fixed_range is true we use the seed_pixel +/- tolerance
If fixed_range is false, the tolerance is +/- tolerance of the values of
the adjacent pixels to the pixel under test.
* *mask* - An optional mask image that can be used to control the flood fill operation.
the output of this function will include the mask data in the input mask.
**RETURNS**
An Image where the values similar to the seed pixel have been replaced by the input color.
**EXAMPLE**
>>> img = Image("lenna")
>>> mask = img.edges()
>>> mask= img.floodFillToMask(((10,10),(54,32)),tolerance=(10,10,10),mask=mask)
>>> mask.show
**SEE ALSO**
:py:meth:`floodFill`
:py:meth:`findFloodFillBlobs`'

def floodFillToMask(self, points, tolerance=None, color=Color.WHITE, lower=None, upper=None, fixed_range=True, mask=None):

    mask_flag = 255
    if isinstance(color, np.ndarray):
        color = color.tolist()
    elif isinstance(color, dict):
        color = (color['R'], color['G'], color['B'])
    if isinstance(points, tuple):
        points = np.array(points)
    if ((upper is None) and (lower is None) and (tolerance is None)):
        upper = (0, 0, 0)
        lower = (0, 0, 0)
    if ((tolerance is not None) and (isinstance(tolerance, float) or isinstance(tolerance, int))):
        tolerance = (int(tolerance), int(tolerance), int(tolerance))
    if ((lower is not None) and (isinstance(lower, float) or isinstance(lower, int))):
        lower = (int(lower), int(lower), int(lower))
    elif (lower is None):
        lower = tolerance
    if ((upper is not None) and (isinstance(upper, float) or isinstance(upper, int))):
        upper = (int(upper), int(upper), int(upper))
    elif (upper is None):
        upper = tolerance
    if isinstance(points, tuple):
        points = np.array(points)
    flags = ((mask_flag << 8) + 8)
    if fixed_range:
        flags = (flags + cv.CV_FLOODFILL_FIXED_RANGE)
    localMask = None
    if (mask is None):
        localMask = cv.CreateImage(((self.width + 2), (self.height + 2)), cv.IPL_DEPTH_8U, 1)
        cv.Zero(localMask)
    else:
        localMask = mask.embiggen(size=((self.width + 2), (self.height + 2)))._getGrayscaleBitmap()
    bmp = self.getEmpty()
    cv.Copy(self.getBitmap(), bmp)
    if (len(points.shape) != 1):
        for p in points:
            cv.FloodFill(bmp, tuple(p), color, lower, upper, flags, localMask)
    else:
        cv.FloodFill(bmp, tuple(points), color, lower, upper, flags, localMask)
    retVal = Image(localMask)
    retVal = retVal.crop(1, 1, self.width, self.height)
    return retVal
