FloodFill 算法填充超出指定边界

FloodFill algorithm fills beyond the specified boundries

我想用洪水填充下面张贴的图像的特定区域"the rectangle on the left side"。为了填充该区域,我在该矩形内指定了一个点以了解像素值,如下所示:

    Log.D(TAG, "", "PixVal: "+gsMat.get(100, 240)[0]);//at that position the pixVal is 91 up ok
    Log.D(TAG, "", "PixVal: "+gsMat.get(250, 60)[0]);//at that position the pixVal is 217 l ??peoblem
    Log.D(TAG, "", "PixVal: "+gsMat.get(330, 310)[0]);//at that position the pixVal is 123 down ok
    Log.D(TAG, "", "PixVal: "+gsMat.get(330, 580)[0]);//at that position the pixVal is 84 r ok

而且我确定点 (x= 60, y= 250) 位于左侧的矩形内。我写了下面的代码来填充那个区域。但我得到了下面张贴的图片作为结果

"Mat subbed = gsRawMat.submat(r)" shows the whole orignal image as if the the whole pixel values in the image lays within the range of 216 to 218?

"ImageUtils.showMat(subbed, "subbed");" shows a white image as if the the whole pixel values in the image lays within the range of 216 to 218, hence, the whole area painted in white (255)?

请告诉我为什么会出现这种行为

代码:

    Mat m = new Mat();
    Rect r = new Rect();
    Imgproc.floodFill(gsMat,
            m,
            new Point(60, 250),
            new Scalar(255),//to fill the designated area with color(255)
            r,//the rect that will encompass the designated area
            new Scalar(216),//lower bound
            new Scalar(218),//upper bound
            Imgproc.FLOODFILL_FIXED_RANGE);

    Mat subbed = gsRawMat.submat(r);// to extract the rectangle contains the flooded area from the main image
    ImageUtils.showMat(gsMat, "gsMat");//to show the gsmat
    ImageUtils.showMat(subbed, "subbed");//to show the subbed area from the gsMat

结果 gsMat

结果胶垫

这个函数我没用过,但是根据(C++)文档,参数不是"lower bound"和"upper bound",而是"lower difference"和"upper difference"。他们的brightness/color值是相对于种子点x=60,y=250的。我还没来得及想清楚,难道这就是责任?

http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#floodfill