Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5 Matlab EMGUCV
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 2-Oct-11 6:19am
J imran1.1K
Edited 2-Oct-11 8:12am
v2
Comments
André Kraak at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
	
 
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
  Permalink  
v8
Comments
C_Johnson at 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)

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 205
2 Prakriti Goyal 177
3 jlopez788 134
4 _Amy 110
0 OriginalGriff 6,762
1 Sergey Alexandrovich Kryukov 5,539
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 30 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100