12,448,720 members (53,689 online)
Rate this:
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 2-Oct-11 6:19am
J imran1.3K
Updated 2-Oct-11 8:12am
v2
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.

Rate this:

## 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
v8
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

Top Experts
Last 24hrsThis month
 ppolymorphe 190 Richard Deeming 160 Jochen Arndt 155 F-ES Sitecore 155 OriginalGriff 140
 OriginalGriff 5,683 Karthik Bangalore 3,335 ppolymorphe 3,262 Maciej Los 2,872 Richard Deeming 2,695