Fast adaptive threshold for Canny Edge Detector in Android

According to my research, Canny Edge Detector is very useful for detecting image edges. After I put a lot of effort into it, I discovered that the OpenCV function can do this, which

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

But for a low threshold and a high threshold, I know that another image has a different threshold, so can I know if there is any quick way of adaptive threshold that can automatically assign a low and high threshold according to another image?

+4
source share
2 answers

This is relatively easy to do. Check out this older post on this .

A quick way is to calculate the mean and standard deviation of the current image and apply a standard deviation of +/- to the image.

An example in C ++ would be something like this:

 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 calculate the median of the image and the target ratio above and below the median (for example, 0.66*medianValue and 1.33*medianValue ).

Hope this helps!

+5
source

Opencv has an adaptive threshold function. With OpenCV4Android it is something like this:

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

Example:

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

Regarding the choice of parameters, you should read the documents for more details. Choosing the right threshold for each image is a completely different matter.

+3
source

Source: https://habr.com/ru/post/1437321/


All Articles