Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:12:58+00:00 2026-05-25T01:12:58+00:00

How can I fill the holes in binary image in emgu cv? In Aforge.net

  • 0

How can I fill the holes in binary image in emgu cv?
In Aforge.net it’s easy, use Fillholes class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:12:58+00:00Added an answer on May 25, 2026 at 1:12 am

    Yes there is a method but it’s a bit messy as its based on cvFloodFill operation. Now all this algorithm is designed to do is fill an area with a colour until it reaches an edge similar to a region growing algorithm. To use this effectively you need to use a little inventive coding but I warn you this code is only to get you started it may require re-factoring to speed things up . As it stands the loop goes through each of your pixels that are less then 255 applies cvFloodFill checks what size the area is and then if it is under a certain area fill it in.

    It is important to note that a copy of the image is made of the original image to be supplied to the cvFloodFill operation as a pointer is used. If the direct image is supplied then you will end up with 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);
                            //CvInvoke.cvFloodFill(
                            CvInvoke.cvFloodFill(image_copy.Ptr, point1, new MCvScalar(255, 255, 255, 255),
                            new MCvScalar(0, 0, 0),
                            new MCvScalar(0, 0, 0), out comp,
                            Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED,
                            Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask.Ptr);
                            if (comp.area < 10000)
                            {
                                image = image_copy.Copy();
                            }
                        }
                    }
                }
    }
    

    The “new MCvScalar(0, 0, 0), new MCvScalar(0, 0, 0),” are not really important in this case as you are only filling in results of a binary image. YOu could play around with other settings to see what results you can achieve. “if (comp.area < 10000)” is the key constant to change is you want to change what size hole the method will fill.

    These are the results that you can expect:

    Original

    Original Image

    Results

    The Resultant Image

    The problem with this method is it’s extremely memory intensive and it managed to eat up 6GB of ram on a 200×200 image and when I tried 200×300 it ate all 8GB of my RAM and brought everything to a crashing halt. Unless a majority of your image is white and you want to fill in tiny gaps or you can minimise where you apply the method I would avoid it. I would suggest writing you own class to examine each pixel that is not 255 and add the number of pixels surrounding it. You can then record the position of each pixel that was not 255 (in a simple list) and if your count was bellow a threshold set these positions to 255 in your images (by iterating though the list).

    I would stick with the Aforge FillHoles class if you do not wish to write your own as it is designed for this purpose.

    Cheers

    Chris

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC view and related model. How can I fill its
I have a from where you can fill in any combination of your home,
I know in C++ and in PHP you can fill a string or a
I have an ecommerce gift store where users can fill out a gift-card for
I'm a pretty new C# programmer. I was wondering if someone can fill me
On a CAShapeLayer , I've drawn a closed UIBezierPath . I can fill this
Hi Can somebody fill me in on JavaScript Testing Frameworks? I'm working on a
How can I fill a array with the data provided by one List? For
I want to know how can i fill only certain columns while filling the
Can any of STL algorithms/container operations like std::fill , std::transform be executed in parallel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.