'The method generates disparity map from set of stereo images.
**PARAMETERS**
* *method* :
*BM* - Block Matching algorithm, this is a real time algorithm.
*SGBM* - Semi Global Block Matching algorithm, this is not a real time algorithm.
*GC* - Graph Cut algorithm, This is not a real time algorithm.
* *nDisparity* - Maximum disparity value. This should be multiple of 16
* *scale* - Scale factor
**RETURNS**
Return None if it fails.
Returns Disparity Map Image
**EXAMPLE**
>>> img1 = Image("sampleimages/stereo_view1.png")
>>> img2 = Image("sampleimages/stereo_view2.png")
>>> stereoImg = StereoImage(img1,img2)
>>> disp = stereoImg.findDisparityMap(method="BM")'

def findDisparityMap(self, nDisparity=16, method='BM'):

    gray_left = self.ImageLeft.getGrayscaleMatrix()
    gray_right = self.ImageRight.getGrayscaleMatrix()
    (r, c) = self.size
    scale = int(self.ImageLeft.depth)
    if ((nDisparity % 16) != 0):
        if (nDisparity < 16):
            nDisparity = 16
        nDisparity = ((nDisparity / 16) * 16)
    try:
        if (method == 'BM'):
            disparity = cv.CreateMat(c, r, cv.CV_32F)
            state = cv.CreateStereoBMState()
            state.SADWindowSize = 41
            state.preFilterType = 1
            state.preFilterSize = 41
            state.preFilterCap = 31
            state.minDisparity = (-8)
            state.numberOfDisparities = nDisparity
            state.textureThreshold = 10
            state.uniquenessRatio = 15
            cv.FindStereoCorrespondenceBM(gray_left, gray_right, disparity, state)
            disparity_visual = cv.CreateMat(c, r, cv.CV_8U)
            cv.Normalize(disparity, disparity_visual, 0, 256, cv.CV_MINMAX)
            disparity_visual = Image(disparity_visual)
            return Image(disparity_visual.getBitmap(), colorSpace=ColorSpace.GRAY)
        elif (method == 'GC'):
            disparity_left = cv.CreateMat(c, r, cv.CV_32F)
            disparity_right = cv.CreateMat(c, r, cv.CV_32F)
            state = cv.CreateStereoGCState(nDisparity, 8)
            state.minDisparity = (-8)
            cv.FindStereoCorrespondenceGC(gray_left, gray_right, disparity_left, disparity_right, state, 0)
            disparity_left_visual = cv.CreateMat(c, r, cv.CV_8U)
            cv.Normalize(disparity_left, disparity_left_visual, 0, 256, cv.CV_MINMAX)
            disparity_left_visual = Image(disparity_left_visual)
            return Image(disparity_left_visual.getBitmap(), colorSpace=ColorSpace.GRAY)
        elif (method == 'SGBM'):
            try:
                import cv2
                ver = cv2.__version__
                if ver.startswith('$Rev    :'):
                    logger.warning("Can't    use    SGBM    without    OpenCV    >=    2.4.0")
                    return None
            except:
                logger.warning("Can't    use    SGBM    without    OpenCV    >=    2.4.0")
                return None
            state = cv2.StereoSGBM()
            state.SADWindowSize = 41
            state.preFilterCap = 31
            state.minDisparity = 0
            state.numberOfDisparities = nDisparity
            state.disp12MaxDiff = 1
            state.fullDP = False
            state.P1 = (((8 * 1) * 41) * 41)
            state.P2 = (((32 * 1) * 41) * 41)
            state.uniquenessRatio = 15
            disparity = state.compute(self.ImageLeft.getGrayNumpy(), self.ImageRight.getGrayNumpy())
            return Image(disparity)
        else:
            logger.warning('Unknown    method.    Choose    one    method    amoung    BM    or    SGBM    or    GC    !')
            return None
    except:
        logger.warning('Error    in    computing    the    Disparity    Map,    may    be    due    to    the    Images    are    stereo    in    nature.')
        return None
