0

I need to use the floodFill function of EMGUCV in C#.

I managed to use it like this:

        Image<Gray, Byte> img = new Image<Gray, byte>(this.B);
        img.Save("orig.png");
        int height = img.Rows;
        int width = img.Cols;
        Point s = new Point( 227, 295);
        int tol = 8;
        Mat outputMask = new Mat(height + 2, width + 2, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Rectangle dummyRect = new Rectangle();
        CvInvoke.FloodFill(img,
                           outputMask,
                           s,
                           new MCvScalar(255, 0, 0),
                           out dummyRect,
                           new MCvScalar(tol), new MCvScalar(tol),
                           Emgu.CV.CvEnum.Connectivity.EightConnected);
        //Emgu.CV.CvEnum.FloodFillType.MaskOnly);
        img.Save("imgModif.png");
        Console.Write("End");

However the output I get in img (or in outputMask) when I use it does not make any sense at all. Some white rectangular areas. I am expecting the results of a "photoshop like" magic wand. ANy idea of what is wrong? Moreover, even though I specify (255,0,0) as the fill color, the result is white in img. (B is a preloaded Bitmap image)

I am trying to do the same as this:

http://www.andrew-seaford.co.uk/flood-fill-opencv/

except I work with a grayscale image initially.

THis is what i get if I set the tol=255 (which should fill the whole image in white, if this function was really behaving like a magic wand):

Lena tol=255

This ''rectangle'' that can be seen does not make sense, even worse, you can see some white pixels going out of this rectangle region (on Lena's hat)... so it does not even seem to be a sort of rectangular constraint. Also a few pixels in the "pseudo rectangle" are not white... I would be curious if someone could test this function on their system with a lena image.

SheppLogan
  • 322
  • 3
  • 18
  • You should a screen shot of the issue. – aybe Mar 31 '19 at 02:57
  • Often floodfill is relying on the color being replaced to be 100% uniform. If it isn't maybe you can add some tolerance. If you can't modify it maybe [this](https://stackoverflow.com/questions/45290317/how-can-i-fill-part-of-image-with-color/45299760#45299760) example helps. It also will only work with a uniform area but you easily add tolerance be replacing `if (cx == c0)` with a condition like `if colordistance(cx, c0) < epsilon)`.. - But doesn't the tol param set a tolerance of 8 ?? Maybe you need more? – TaW Mar 31 '19 at 07:27
  • I am only working with grayscale. Yes I changed the tolerance bounds (lower, upper) I don't really see what you mean by uniform (for me, in grayscale, that would be a tolerance of 0 i.e. only pixels of the same intensity that are 8-connected) – SheppLogan Mar 31 '19 at 14:15

0 Answers0