Automatic calculation of low and high thresholds for the Canny operation in opencv

后端 未结 7 917
孤独总比滥情好
孤独总比滥情好 2020-11-28 03:15

In openCV, the low and high thresholds for the canny operator are mandatory:

cvCanny(input,output,thresh1,thresh2)

In Matlab, there\'s an o

7条回答
  •  不知归路
    2020-11-28 03:30

    I have another approach to the same problem. This solution also involves selection of optimal thresholds for edge detection.

    • First compute the median of the gray scale image.
    • Choose two values (lower and upper thresholds) based on the median value of the gray scale image.

    The following pseudo-code shows you how its done:

    v = np.median(gray_img)
    sigma = 0.33
    
    #---- apply optimal Canny edge detection using the computed median----
    lower_thresh = int(max(0, (1.0 - sigma) * v))
    upper_thresh = int(min(255, (1.0 + sigma) * v))
    

    Fix these thresholds as parameters in the canny edge detection function.

    Illustration: If you observe a Gaussian curve in statistics, values between 0.33 from both sides of the curve are considered in the distribution. Any value outside these points are assumed to be outliers. Since images are considered to be data, this concept is assumed here as well.

提交回复
热议问题