如何去除此图像中的噪声 -openCV [英] How can i remove noise in this image -openCV

查看:57
本文介绍了如何去除此图像中的噪声 -openCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试消除此图像中的噪点:

I'm trying to remove the noise in this image:

旨在隔离三角形.

实际上我有很多这样的图片(带有一些噪音的三角形),我不知道如何去除噪音.我想要一个没有噪声的大三角形以便对其进行处理(检测兴趣点).

Actually i have a lot of picture like that (triangle with some noise) and i don't know how can i remove noise. I want to have a great triangle without noise in order to process it (detect interest points).

我尝试过侵蚀和所有这些东西,但没有成功.你知道我如何改进这个结果吗?

I have tried erode and all theses stuff but without success. Do you have an idea about how i can improve this result?

推荐答案

腐蚀和随后的膨胀会扭曲三角形的形状.您可以使用 连接组件 (CC) 或者更好的 floodFill 并根据面积移除(用零填充)(floodFill 输出它找到的每个 CC 的面积).当然,如果您确定要保留的始终是三角形,则可以在擦除噪声之前添加额外的步骤来验证三角形.下面的代码找到最大的线段并用红色勾勒出它的轮廓.三角形形状的验证由绿色圆圈表示,可以通过查看 approx 向量中的多边形近似来进一步探索.

Eroding with subsequent dilation will distort the shape of your triangles. You can use connected components (CC) or even better a floodFill and remove (fill with zeros) based on the area (floodFill outputs the area of every CC it finds). Of course if you are sure that what you want to preserve is always triangles you can add an extra step to verify a triangular shape before erasing noise. The code below finds the largest segment and outlines its contour in red. Verification of triangle shape is indicated by green circles and can be further explored by a looking at a polygonal approximation in approx vector.

vector<vector<Point> > contours;
Mat hierarchy, I Icol; 
Icol = imread("triang.png");
cvtColor(Icol, I, CV_BGR2GRAY);

// Find connected components (CC)
findContours(I.clone(), contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

// Select the largest CC 
int ncontours = contours.size();
int max_sz = 0, max_idx;
for (int i=0; i<ncontours; i++) {
    int sz = contours[i].size();
    if (max_sz<sz) {
        max_sz = sz;
        max_idx = i;
    }
}
for (int i=0; i<max_sz; i++) {
    Point pt = contours[max_idx][i];
    Icol.at<Vec3b>(pt.y, pt.x) = Vec3b(0, 0, 255);
}

// Verify triangle
vector<Point> approx;
approxPolyDP(contours[max_idx], approx, 10, true);
cout<<Mat(approx)<<endl;
for (int i=0; i<approx.size(); i++) {
    Point pt = approx[i];
    circle(Icol, pt, 3, Scalar(0, 255, 0), 2);
}
imshow("largest", Icol); imwrite("triangle.png", Icol);
waitKey(-1);

这篇关于如何去除此图像中的噪声 -openCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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