本文介绍了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.
推荐答案
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)等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!