Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. After I put many effort on it, I found that OpenCV function can do that, which is

    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?

like image 380
Hua Er Lim Avatar asked Oct 02 '12 03:10

Hua Er Lim


People also ask

How do you set the threshold in Canny edge detection?

The 'Canny' method uses two thresholds. For example, if the threshold is [0.1 0.15] then the edge pixels above the upper limit(0.15) are considered and edge pixels below the threshold(0.1) are discarded. Now, you may have a question "what about the pixels in between upper and lower threshold"?

How is hysteresis thresholding used in the Canny edge detector?

Hysteresis counters streaking by setting an upper and lower edge value limit. Considering a line segment, if a value lies above the upper threshold limit it is immediately accepted. If the value lies below the low threshold it is immediately rejected.

What is double thresholding in Canny edge detection?

The Canny edge detection algorithm uses double thresholding. Edge pixels stronger than the high threshold are marked as strong; edge pixels weaker than the low threshold are suppressed and edge pixels between the two thresholds are marked as weak.

What is threshold in edge detection?

Index Terms— Colour images Edge detection, threshold Image segmentation is the process of partitioning/ subdividing a digital image into multiple meaningful regions or sets of pixels regions with respect to a particular application [1].


1 Answers

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

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:

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 (e.g., 0.66*medianValue and 1.33*medianValue).

Hope that helps!

like image 89
mevatron Avatar answered Sep 28 '22 07:09

mevatron