简体   繁体   English

Android中Canny边缘检测器的快速自适应阈值

[英]Fast Adaptive Threshold for Canny Edge Detector in Android

According to my research, Canny Edge Detector is very useful for detecting the edge of an image. 根据我的研究,Canny Edge Detector对于检测图像边缘非常有用。 After I put many effort on it, I found that OpenCV function can do that, which is 在我付出很多努力之后,我发现OpenCV函数可以做到这一点,也就是说

    Imgproc.Canny(Mat image, Mat edges, double threshold1, double threshold2)

But for the low threshold and high threshold, I know that different image has different threshold, so can I know if there are any fast adaptive threshold method can automatically assign the low and high threshold according to different image? 但是对于低阈值和高阈值,我知道不同的图像有不同的阈值,所以我知道是否有任何快速自适应阈值方法可以根据不同的图像自动分配低和高阈值?

This is relatively easy to do. 这相对容易。 Check out this older SO post on the subject. 查看关于该主题的这篇较旧的SO帖子

A quick way is to compute the mean and standard deviation of the current image and apply +/- one standard deviation to the image. 一种快速方法是计算当前图像的平均值和标准偏差,并对图像应用+/-一个标准偏差。

The example in C++ would be something like: C ++中的示例如下:

Mat img = ...;
Scalar mu, sigma;
meanStdDev(img, mu, sigma);

Mat edges;
Canny(img, edges, mu.val[0] - sigma.val[0], mu.val[0] + sigma.val[0]);

Another method is to compute the median of the image and target a ratio above and below the median (eg, 0.66*medianValue and 1.33*medianValue ). 另一种方法是计算图像的中值并且目标是中值之上和之下的比率(例如, 0.66*medianValue1.33*medianValue )。

Hope that helps! 希望有所帮助!

Opencv has an adaptive threshold function. Opencv具有自适应阈值功能。 With OpenCV4Android it is like this: 使用OpenCV4Android,它是这样的:

Imgproc.adaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, C);

An example: 一个例子:

Imgproc.adaptiveThreshold(mInput, mInput, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 15, 4);

As for how to choose the parameters, you have to read the docs for more details. 至于如何选择参数,您必须阅读文档以获取更多详细信息。 Choosing the right threshold for each image is a whole different question. 为每个图像选择正确的阈值是一个完全不同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM