Hello !

Began to deal with the Сanny Edge edge Сanny Edge detection detector. The general picture (although at a very superficial level) I understood a little, but I can’t figure out why we need such things as:

  1. Threshold (thresholds) - there is a minimum and maximum.
  2. Kernel size (grid) - here in the example they use the 3x3 value

And another question, can someone tell me the literature on this topic? I am very interested in how it works. All I have found is this , from the documentation of the OpenCV library and from this nice article . Thank !

    1 answer 1

    The thresholds are arbitrary values ​​used by the Canny algorithm to decide on each of the pixels at the final stage of their work. There are only two thresholds: upper and lower.

    If the magnitude of the gradient of each individual pixel is greater than the upper threshold, then this pixel is considered the border. If the value of the magnitude of the gradient is less than the lower threshold, then that pixel is discarded (no longer taken into account).

    If the magnitude of the pixel gradient is between the thresholds, then in this situation, in different implementations of the algorithm, either a separate check is carried out, focusing on the values ​​and directions of the gradient of adjacent pixels, or, as is the case in OpenCV, mark it as a border provided that the pixel in question is adjacent to a pixel with a gradient magnitude value greater than the upper threshold.

    The kernel size ( kernel size or aperture size ) is the size of the square convolution matrixes ( convolution ), which are used to calculate the gradient in the vertical and horizontal directions. In the case of OpenCV, only "3", "5" or "7" can be valid kernel size values. This function is performed by the Sobel operator, which is transparently called in the Canny() function.

    Convolution with respect to images is essentially the operation of calculating a new value for each pixel based on the values ​​of other pixels that are its neighbors. In addition to the image itself, a separate matrix, often called a window or filter, is involved in the convolution. Usually use a square, with an equal, but an odd number of rows and columns. Oddness is needed in order to generally get the central element of the matrix or, otherwise, the so-called anchor:

     ( )( )( ) ( )(x)( ) ( )( )( ) 

    In the process of convolving, an anchor is superimposed on each pixel of the original image, thereby covering all the pixels adjacent to the current one with a filter. Then the sum of the products of the pixel values ​​by the values ​​of the corresponding filter elements is calculated, which will be the new pixel value.

    • For some reason I knew exactly what you would answer! Thank you very much, have a nice day :) - kxko
    • Thank you :) In fact, there are a lot of participants on ru.so who are well versed in the subject of computer vision. It’s just that questions have become rare recently and, accordingly, the activity in the answers has fallen compared with the earlier period. But it seems to me that this matter will gradually get better, even if one tries to take an active part in the answers. We'll see :) - alexis031182