'**SUMMARY**
Implements the Watershed algorithm on the input image.
Read more:
Watershed: "http://en.wikipedia.org/wiki/Watershed_(image_processing)"
**PARAMETERS**
* *mask* - an optional binary mask. If none is provided we do a binarize and invert.
* *erode* - the number of times to erode the mask to find the foreground.
* *dilate* - the number of times to dilate the mask to find possible background.
* *useMyMask* - if this is true we do not modify the mask.
**RETURNS**
The Watershed image
**EXAMPLE**
>>> img = Image("/sampleimages/wshed.jpg")
>>> img1 = img.watershed()
>>> img1.show()
# here is an example of how to create your own mask
>>> img = Image(\'lenna\')
>>> myMask = Image((img.width,img.height))
>>> myMask = myMask.floodFill((0,0),color=Color.WATERSHED_BG)
>>> mask = img.threshold(128)
>>> myMask = (myMask-mask.dilate(2)+mask.erode(2))
>>> result = img.watershed(mask=myMask,useMyMask=True)
**SEE ALSO**
Color.WATERSHED_FG - The watershed foreground color
Color.WATERSHED_BG - The watershed background color
Color.WATERSHED_UNSURE - The watershed not sure if fg or bg color.
TODO: Allow the user to pass in a function that defines the watershed mask.'

def watershed(self, mask=None, erode=2, dilate=2, useMyMask=False):

    try:
        import cv2
    except ImportError:
        logger.warning('OpenCV    >=    2.3.0    required')
        return None
    output = self.getEmpty(3)
    if (mask is None):
        mask = self.binarize().invert()
    newmask = None
    if (not useMyMask):
        newmask = Image((self.width, self.height))
        newmask = newmask.floodFill((0, 0), color=Color.WATERSHED_BG)
        newmask = ((newmask - mask.dilate(dilate)) + mask.erode(erode))
    else:
        newmask = mask
    m = np.int32(newmask.getGrayNumpyCv2())
    cv2.watershed(self.getNumpyCv2(), m)
    m = cv2.convertScaleAbs(m)
    (ret, thresh) = cv2.threshold(m, 0, 255, cv2.cv.CV_THRESH_OTSU)
    retVal = Image(thresh, cv2image=True)
    return retVal
