FloodFill算法填充超出指定的边界

时间:2015-07-12 10:09:39

标签: java opencv image-processing edge-detection flood-fill

我想要填充下面张贴图片的某个区域“左侧的矩形”。要填充该区域,我在该矩形内指定了一个点,以便知道像素的值,如下所示:

    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 enter image description here

结果底垫enter image description here

1 个答案:

答案 0 :(得分:1)

我没有使用过这个函数,但根据(C ++)文档,参数不是“下限”和“上限”,而是“下差”和“上差”。它们的亮度/颜色值相对于种子点x = 60,y = 250.我没有时间考虑它,但这可能是负责任的吗?

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