Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a black and white picture on which I want to remove white areas that are more than 50 pixels.
I found bwareaopen in MATLAB for this purpose. I am using EMGU and want equivalent in EMGU.

Thank you for helping.
Posted
Updated 2-Oct-11 8:12am
v2
Comments
André Kraak 2-Oct-11 13:07pm    
Please share any relevant code with us, seeing the code might us help understand the problem you are facing.

If you wish to change your question use the Improve Question button.

1 solution

Hi,

Well in short NO there is not a built in function that performs the same operation as bwareaopen.

You will simply have to loop through your image and look for a white pixel.

When you find 1 make a blank copy or a list of points that records all pixels attached to the original that are also white. If it is less than 50 pixel then set all these co-ordinates to black else leave it. Use the collection of lists or an overall list/image map to make sure you don't look at pixels you've already checked.

While this process may seem slow it isn't when your talking small areas of white however you may wish to look at some optimisation if a lot of your image is white. Say reduce your image 50% and look for areas less than 10 pixels.

You speed will be comparable to bwareaopen as this is performing the same operation.

Cheers
Chris

[EDIT]
I have found a method of implementing a bwareaopen on the opencv yahoo group many thanks to M.Klien for converting the method.

http://tech.groups.yahoo.com/group/OpenCV/message/27345[^]

In EMGU the equivalent code in a method is:

C#
private Image<Bgr, byte > bwareaopen(Image<Bgr, byte > Input_Image, int threshold)
{

    Image<Bgr, byte> bwresults = Input_Image.Copy();

    using (MemStorage storage = new MemStorage())
    {
        for (Contour<Point> contours = Input_Image.Convert<Gray, byte>().FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); contours != null; contours = contours.HNext)
        {
            Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
            if (currentContour.Area < threshold) 
            {
                for (int i = currentContour.BoundingRectangle.X; i < currentContour.BoundingRectangle.X + currentContour.BoundingRectangle.Width; i++)
                {
                    for (int j = currentContour.BoundingRectangle.Y; j < currentContour.BoundingRectangle.Y + currentContour.BoundingRectangle.Height; j++)
                    {
                        bwresults.Data[j, i, 0] = 0;
                        bwresults.Data[j, i, 1] = 0;
                        bwresults.Data[j, i, 2] = 0;
                    }
                }
            }
        }
    }
    return bwresults;
}


Cheers, Chris
 
Share this answer
 
v8
Comments
C_Johnson 30-Nov-11 12:12pm    
I hate the formatting on here at times, I will keep trying to get the code up here correctly!...

At last, these ">" characters are a pain

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900