# Threshold Value of Canny

Hello, I have a question regarding the threshold parameters of canny. My assumption was that threshold 1 and 2 can be values between 0 and 255. However, if I use thresholds above 255 the algorithm still detects edges. How is that possible if the maximum brightness of a pixel is 255? The official docs dont say anything about how the threshold works internally.

welcome.

always work with the documentation, and wherever it leads (wikipedia in this instance):

https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de

thresholds 1 and 2 are for hysteresis.

a line is only started when a gradient is above the higher threshold. it is continued as long as gradients are above the lower threshold (even if theyâ€™re below the higher threshold).

docs donâ€™t say which is which.

I do understand what the thresholds do in theory, what i dont understand is why lines are detected if I set the thresholds to for example: 400 and 500. My conclusion to this is that the gradients can have values over 255 for some reason.

Im doing an assignment for university and Im supposed to recreate opencv filters from scratch and then compare them. So I wanted to match the visual output of the opencv and my own filter as close as I can. But because I dont know what is going on with the thresholds internally I cant do that. In my own filter I know that the threshold is simply a value between 0 and 255.

Well, it is very common for programs to silently accept parameter values higher than they actually can use and just use the max value if the value is higherâ€¦ (And I guess you shouldnâ€™t worry about behaviour with illegal outside-of-domain values)

1 Like

pure speculation: maybe itâ€™s calculating gradients on all three color channels, and simply adding each gradient magnitude. that ought to give a range of 255*3 = 765â€¦ the effects of which you should only be able to see if you have synthetically sharp contrasts.