本文介绍了如果阈值不好,如何检测opencv(c ++)中的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有这样的灰度图像: 我想检测这种异常现象图片。在第一张图片(左上角)我要检测三个点,在第二张图片(右上角)有一个小点和一个Foggy区域(在右下角),在最后一个,那里在图像中间的某处也是一个小点。 正常的静态阈值对我来说不行,Otsu的方法也是最好的选择。是否有更好,更强大或更智能的方法来检测这样的异常?在Matlab中,我使用的是Frangi Filtering(特征值过滤)。任何人都可以提出良好的处理算法来解决像这样的表面上的异常检测吗? 编辑:添加了另一张标有异常的图片: 这是我的代码如何使用tophat过滤和对比度调整: kernel = getStructuringElement(MORPH_ELLIPSE,Size(3,3),Point(0,0)); morphologyEx(inputImage,imgFiltered,MORPH_TOPHAT,kernel,Point(0,0),3); imgAdjusted = imgFiltered * 7.2; 结果如下: 如何从最后一张图片中分割异常仍有疑问?所以如果有人知道如何解决它,那就拿吧! :) ?? 解决方案你应该看看底帽过滤。它被定义为原始图像与图像形态闭合的差异,它会使您正在寻找的细节等细节消失。 我调整了对比度以使两个图像都可见。在查看强度时,异常更加明显,并且更容易分割出来。 让我们来看看第一张图片: 由于可视化引起的缩放,直方图值不能代表现实我正在使用的工具。但相对距离确实如此。所以现在阈值范围要大得多,目标从窗口变为谷仓门。 全局阈值(强度> 15): Otsu的方法在这里运作不佳。它将所有小细节分割到前景。 通过形态学开放消除噪音后: 我还假设黑点是您感兴趣的异常。通过设置较低的阈值,您可以包含更多的表面细节。例如,第三张图片没有任何特别有趣的功能,但是你可以判断。就像m3h0w所说的那样,知道如果你的眼睛很难判断某些东西对计算机来说可能是不可能的,这是一个很好的启发式方法。 I have grayscale images like this:I want to detect anomalies on this kind of images. On the first image (upper-left) I want to detect three dots, on the second (upper-right) there is a small dot and a "Foggy area" (on the bottom-right), and on the last one, there is also a bit smaller dot somewhere in the middle of the image.The normal static tresholding does't work ok for me, also Otsu's method is always the best choice. Is there any better, more robust or smarter way to detect anomalies like this? In Matlab I was using something like Frangi Filtering (eigenvalue filtering). Can anybody suggest good processing algorithm to solve anomaly detection on surfaces like this?EDIT: Added another image with marked anomalies:Using @Tapio 's tophat filtering and contrast adjustement.Since @Tapio provide us with great idea how to increase contrast of anomalies on the surfaces like I asked at the begining, I provide all you guys with some of my results. I have and image like this:Here is my code how I use tophat filtering and contrast adjustement:kernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3), Point(0, 0));morphologyEx(inputImage, imgFiltered, MORPH_TOPHAT, kernel, Point(0, 0), 3);imgAdjusted = imgFiltered * 7.2;The result is here:There is still question how to segment anomalies from the last image?? So if anybody have idea how to solve it, just take it! :) ?? 解决方案 You should take a look at bottom-hat filtering. It's defined as the difference of the original image and the morphological closing of the image and it makes small details such as the ones you are looking for flare out.I adjusted the contrast to make both images visible. The anomalies are much more pronounced when looking at the intensities and are much easier to segment out.Let's take a look at the first image:The histogram values don't represent the reality due to scaling caused by the visualization tools I'm using. However the relative distances do. So now the thresholding range is much larger, the target changed from a window to a barn door.Global thresholding ( intensity > 15 ) :Otsu's method worked poorly here. It segmented all the small details to the foreground.After removing noise by morphological opening :I also assumed that the black spots are the anomalies you are interested in. By setting the threshold lower you include more of the surface details. For example the third image does not have any particularly interesting features to my eye, but that's for you to judge. Like m3h0w said, it's a good heuristic to know that if something is hard for your eye to judge it's probably impossible for the computer. 这篇关于如果阈值不好,如何检测opencv(c ++)中的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 19:46