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.

Thank you in advance


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

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.