-3

I am trying to perform the Canny edge detection algorithm of OpenCV to an image array, whose values range from 0 to 255.

I am struggling to understand the role of the thresholds in the cv2.canny() function because for example, when I use threshold values of (MinThr=300, MaxThr=400) or (MinThr=350, MaxThr=450) I get different results. I don't understand why this happen since I thought that the Thresholds values that I define, couldn't be higher than the maximum value of the pixels in the array (in my case 255).

The other answers that I saw at Stackoverflow didn't help, so if someone could enlight me I would be very grateful. Thanks.

LuisFigas
  • 3
  • 3
  • Does this answer your question? [opencv canny: Do minVal and maxVal matter if you're working with a black and white image?](https://stackoverflow.com/questions/35102372/opencv-canny-do-minval-and-maxval-matter-if-youre-working-with-a-black-and-whi) – Christoph Rackwitz Jan 28 '22 at 23:06

1 Answers1

1

The thresholds are applied not to the original image intensity, but to its gradient magnitude, which maximal value is about 4 times larger than the maximal image intensity, because it is estimated using the Sobel operator. So you will stop seeing the difference (actually you will get an empty result) when the upper threshold exceeds 1000 and something. For details see Canny tutorial.

aparpara
  • 2,171
  • 8
  • 23
  • 1
    even more than 4 times. see existing question+answer: https://stackoverflow.com/questions/35102372/opencv-canny-do-minval-and-maxval-matter-if-youre-working-with-a-black-and-whi – Christoph Rackwitz Jan 28 '22 at 23:07
  • To be precise, the maximal theoretical Sobel gradient magnitude is 6 times the maximal intensity. It is achieved on `[[255, 255, ?], [255, ?, 0], [?, 0, 0]]` and `[[0, 0, ?], [0, ?, 255], [?, 255, 255]]` (values at positions marked `?` don't matter). No need to test all possible combinations, simple reasoning is sufficient :) But on real images such values are extremely rare unless you deal with some binary drawing. But in this case Canny is most probably an overkill. – aparpara Jan 29 '22 at 10:34