EMGU中的bwareaopen(Matlab)等价 [英] bwareaopen (Matlab) equivelent in EMGU

查看:189
本文介绍了EMGU中的bwareaopen(Matlab)等价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张黑白图片,我想在上面删除超过50个像素的白色区域.
为此,我在MATLAB中找到了bwareaopen.我正在使用EMGU,并希望在EMGU中具有等效功能.

谢谢您的帮助.

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.

推荐答案



总之,没有,没有内置函数执行与bwareaopen相同的操作.

您只需要遍历图像并寻找白色像素即可.

当您找到1时,请制作一个空白副本或一个点列表,其中记录了附加到原始像素上的所有像素,这些像素也是白色的.如果小于50像素,则将所有这些坐标设置为黑色,否则保留它.使用列表集合或整个列表/图像图来确保您不会查看已经检查过的像素.

虽然这个过程看似很慢,但并不是说白色的小区域,但是如果您的图像很多是白色的,您可能希望进行一些优化.假设将您的图片缩小50%,并寻找小于10像素的区域.

您的速度将与bwareaopen相当,因为它执行相同的操作.

干杯
克里斯


我已经找到了一种在opencv雅虎组上实现bwareaopen的方法,这要感谢M.Klien转换了该方法.

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

在EMGU中,方法中的等效代码为:

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


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


这篇关于EMGU中的bwareaopen(Matlab)等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆