opencv中自适应阈值和普通阈值的区别
我有这个灰色视频流:
该图像的直方图:
阈值图像:
threshold( image, image, 150, 255, CV_THRESH_BINARY );
我得到:
>预计。
当我使用以下方法进行自适应阈值处理时:
adaptiveThreshold(image, image,255,ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY,15,-5);
我得到:
这看起来像边缘检测而不是阈值处理。我期望的是黑色和白色区域。所以我的问题是,为什么这看起来像边缘检测而不是阈值处理。
提前谢谢
I have this gray video stream:
The histogram of this image:
The thresholded image by :
threshold( image, image, 150, 255, CV_THRESH_BINARY );
i get :
Which i expect.
When i do adaptive thresholding with :
adaptiveThreshold(image, image,255,ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY,15,-5);
i get :
Which looks like edge detection and not thresholding. What i expected was black and white areas . So my question is, why does this look like edge detection and not thresholding.
thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自适应阈值的工作原理类似于这个:
阈值的工作方式不同:
因此,听起来adaptiveThreshold逐像素计算阈值,而threshold则针对整个图像计算阈值——它用一个标尺测量整个图像,而另一个标尺为每个像素创建一个新的“标尺”。
Adaptive Threshold works like this:
Threshold works differently:
So it sounds like adaptiveThreshold calculates a threshold pixel-by-pixel, whereas threshold calculates it for the whole image -- it measures the whole image by one ruler, whereas the other makes a new "ruler" for each pixel.
我在为 OCR 目的进行自适应阈值处理时遇到了同样的问题。 (抱歉,这是 Python 而不是 C++)
最后一个参数是用于计算每个像素阈值的邻域大小。如果你的邻域太小(我的邻域是 3),它的工作原理类似于边缘检测。一旦我把它做得更大,它就按预期工作了。当然,“正确”的尺寸取决于图像的分辨率以及您正在查看的特征的尺寸。
I had the same issue doing adaptive thresholding for OCR purposes. (sorry this is Python not C++)
The last paramter is the size of the neighborhood used to calculate the threshold for each pixel. If your neighborhood is too small (mine was 3), it works like edge detection. Once I made it bigger, it worked as expected. Of course, the "correct" size will depend on the resolution of your image, and size of the features you're looking at.