Yes, there is a method, but it is a little dirty because it is based on the cvFloodFill operation. Now this whole algorithm is designed to fill the area with color until it reaches an edge similar to the area growth algorithm. To use this effectively, you need to use a little inventive coding, but I warn you that this code is only for you to start, it may require repeated factorization to speed it up. Since it is located, a loop goes through each of your pixels, which is less than 255 applied. CvFloodFill checks the size of the area, and then, if it is under a specific area, fill it.
It is important to note that a copy of the image is made from the original image, which will be passed to the cvFloodFill operation as a pointer. If a direct image is specified, you get a white image.
OpenFileDialog OpenFile = new OpenFileDialog(); if (OpenFileDialog.ShowDialog() == DialogResult.OK) { Image<Bgr, byte> image = new Image<Bgr, byte>(OpenFile.FileName); for (int i = 0; i < image.Width; i++) { for (int j = 0; j < image.Height; j++) { if (image.Data[j, i, 0] != 255) { Image<Bgr, byte> image_copy = image.Copy(); Image<Gray, byte> mask = new Image<Gray, byte>(image.Width + 2, image.Height + 2); MCvConnectedComp comp = new MCvConnectedComp(); Point point1 = new Point(i, j);
"New MCvScalar (0, 0, 0), new MCvScalar (0, 0, 0)" are not really important in this case, because you only fill in the results of the binary image. You can play with other settings to see what results you can achieve. "if (comp.area <10000)" is the key constant for the change, you want to change which hole the method will fill.
These are the results you can expect:
Original

results

The problem with this method is the extremely heavy memory usage, and he managed to eat 6 GB of RAM in a 200x200 image, and when I tried to use 200x300, he ate all 8 GB of my RAM and brought everything to a stop. If most of your image is not white and you want to fill in tiny gaps, or you can minimize where you apply the method, I would avoid this. I would suggest writing your own class to examine each pixel that is not 255, and add the number of pixels surrounding it. Then you can record the position of each pixel that was not 255 (in a simple list), and if your counter was below a threshold value, set these positions to 255 in your images (by repeating the list).
I would stick with the Aforge FillHoles class if you don't want to write your own, as it is designed for that purpose.
Greetings
Chris