Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best value for threshold in Canny

I have an image which I want to detect edges on that. I found Canny has been used a lot ( I don't know whether I have a better option than that). I have set the values as follow:

  Imgproc.Canny(img, img, 10, 100, 3,true)

I've changed threshold values but don't see that much of a change in my image. Can anyone explain to me if there is a logical way to figure out numbers for threshold values (my image is gray scale)

Thank you...

like image 606
Rubbic Avatar asked Aug 04 '14 18:08

Rubbic


People also ask

How do you choose a Canny threshold?

Canny does use two thresholds (upper and lower): If a pixel gradient is higher than the upper threshold, the pixel is accepted as an edge. If a pixel gradient value is below the lower threshold, then it is rejected.

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].

What are the input parameters for Canny algorithm?

The effect of the Canny operator is determined by three parameters --- the width of the Gaussian kernel used in the smoothing phase, and the upper and lower thresholds used by the tracker.


2 Answers

I think this should be taken case by case, if you post some sample images would be useful, but I will try to answer anyways. Here is from Opencv Documents

Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
where the arguments are:

detected_edges: Source image, grayscale
detected_edges: Output of the detector (can be the same as the input)
lowThreshold: The value entered by the user moving the Trackbar
highThreshold: Set in the program as three times the lower threshold (following Canny’s recommendation)
kernel_size: We defined it to be 3 (the size of the Sobel kernel to be used internally)

What usually works for me is highThreshold = 255 and lowThreshold = 255/3

like image 142
Samer Avatar answered Sep 28 '22 03:09

Samer


You can use this equation it is useful and you can apply bluer to enhance it.

blurred_img = cv2.blur(img,ksize=(5,5))
med_val = np.median(img) 
lower = int(max(0 ,0.7*median_pix))
upper = int(min(255,1.3*median_pix))
edges = cv2.Canny(image=img, threshold1=lower,threshold2=upper)
like image 28
Abdulelah Alkesaiberi Avatar answered Sep 28 '22 04:09

Abdulelah Alkesaiberi