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).