2

I just wanna use the flood fill but it fails and I never used it so i think I am doing something wrong.

Mat flooded=new Mat();
Point flood=new Point(1,1);
// floodedmat = Mat.zeros(myMat2.size(), CvType.CV_8UC1);
Imgproc.floodFill(myMat2, flooded, flood, new Scalar(255, 255, 255));
Utils.matToBitmap(flooded, copy);

After the flood fill I intend to return it to bitmap to display it so I will see changes.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70

1 Answers1

0

You should use the overloaded floodFill method which takes additional parameters:

Imgproc.floodFill(myMat2, flooded, flood, new Scalar(255, 255, 255), new Rect(), lowerDiff, upperDiff, 4);

The new Rect() object is a bounding rectangle which will contain your floodfill; lowerDiff and upperDiff should be initialized scalars with a difference value to your original pixel value (ie: if it's a RGB image with difference in color values, lets say at your seed point (flood) there is a bright yellow pixel and it is surrounded by a slightly less bright or slightly more bright yellow pixels, it will fill them with white color rectangles). You want to initialize them with 3 values, ie:

Scalar lowerDiff = new Scalar(10, 10, 10);

And the final integer argument is how many neighbouring pixels should the floodFill actually take into consideration, 4 is default, 8 is another option. (4 will take northern, eastern, western, and southern pixels, while 8 will take north, north-eastern, eastern, south-eastern, etc.. pixels).

Ognjen Mišić
  • 1,219
  • 17
  • 37