'**SUMMARY**
Smooths the image, with the median filter. Performs a median filtering operation to denoise/despeckle the image.
The optional parameter is the window size.
see : http://en.wikipedia.org/wiki/Median_filter
**Parameters**
* *window* - should be in the form a tuple (win_x,win_y). Where win_x should be equal to win_y. By default it is set to 3x3, i.e window = (3x3).
**Note**
win_x and win_y should be greater than zero, a odd number and equal.
For OpenCV versions <= 2.3.0
this acts as Convience function derived from the :py:meth:`smooth` method. Which internally calls cv.Smooth
For OpenCV versions >= 2.3.0
cv2.medianBlur function is called.'

def medianFilter(self, window='', grayscale=False):

    try:
        import cv2
        new_version = True
    except:
        new_version = False
        pass
    if is_tuple(window):
        (win_x, win_y) = window
        if ((win_x >= 0) and (win_y >= 0) and ((win_x % 2) == 1) and ((win_y % 2) == 1)):
            if (win_x != win_y):
                win_x = win_y
        else:
            logger.warning('The    aperture    (win_x,win_y)    must    be    odd    number    and    greater    than    0.')
            return None
    elif is_number(window):
        win_x = window
    else:
        win_x = 3
    if (not new_version):
        grayscale_ = grayscale
        return self.smooth(algorithm_name='median', aperture=(win_x, win_y), grayscale=grayscale_)
    elif grayscale:
        img_medianBlur = cv2.medianBlur(self.getGrayNumpy(), win_x)
        return Image(img_medianBlur, colorSpace=ColorSpace.GRAY)
    else:
        img_medianBlur = cv2.medianBlur(self.getNumpy()[:, :, ::(-1)].transpose([1, 0, 2]), win_x)
        img_medianBlur = img_medianBlur[:, :, ::(-1)].transpose([1, 0, 2])
        return Image(img_medianBlur, colorSpace=self._colorSpace)
