The principle of edge extraction of canny operator

Organized in Zhihu: Non-maximum suppression in canny

and csdn: canny operator principle

Algorithm principle:

(1) Denoising

The first step is to convolve the original data with a Gaussian mask, and the resulting image is slightly blurred compared to the original image.

(2) Use the finite difference of the first -order partial derivatives to calculate the magnitude and direction of the gradient .

(3) Non-maximum suppression of gradient amplitude.

Only getting the global gradient is not enough to determine the edge, so to determine the edge, it is necessary to keep the point with the largest local gradient and suppress the non-maximum value. (non-maxima suppression, NMS)
solution: use the direction of the gradient.


(4) Detect and connect edges with double-threshold algorithm .

Solution: Double threshold algorithm. The double-threshold algorithm applies two thresholds τ1 and τ2 to the image after non-maximum suppression, and 2τ1≈τ2 . Thereby , two threshold edge images N1[i,j] and N2[i,j] can be obtained (the operation is: respectively <τ1, pixel=0, get N1[i,j]; <τ2, pixel=0, get N2[i,j] ). Since N2[i,j] is obtained using a high threshold, it contains few false edges, but has discontinuities (not closed because the threshold may be relatively too large...) . The double-threshold method needs to connect the edges to the contour in N2[i,j]. When the endpoint of the contour is reached, the algorithm searches for the edge that can be connected to the contour at the 8-neighbor position of N1[i,j] . In this way, The algorithm continuously collects edges in N1[i,j] until N2[i,j] is connected ( based on N2, with the assistance of N1, the connection of the contour lines in N2 is completed... Against N1, put Fill in the N2 that needs to be completed. ) .


Now explain the non-maximal simulation principle of (3):

Non-maximum suppression is to find local pixel maximum points, which can eliminate many non-edge points .

For non-maximum suppression, it is necessary to first determine that the gray value of pixel C is the largest in its 8-value neighborhood , and then find out whether there is a larger value in its gradient direction . The direction of the blue line in Figure 1 is the gradient direction of point C, so that it can be determined that the local maximum value must be distributed on this line, that is, except for point C, the intersection points of the gradient direction dTmp1 and dTmp2 are two points may also be a local maximum. Therefore, by judging the gray level of point C and the gray level of these two points, it can be judged whether point C is the local maximum gray point in its neighborhood. If it is judged that the gray value of point C is smaller than either of these two points, it means that point C is not a local maximum value, then point C can be excluded as an edge . This is how non-maximum suppression works.

In the process of understanding, you need to pay attention to the following two points:

1. Central African maximum suppression is to answer the question: "Is the current gradient value a local maximum in the gradient direction?" So, compare the gradient value at the current position with the gradient values ​​on both sides in the gradient direction.

2. The gradient direction is perpendicular to the edge direction . But actually, we can only get the values ​​of 8 points in the neighborhood of point C, and dTmp1 and dTmp2

It is not among them . To obtain these two values, it is necessary to perform linear interpolation on dTmp1 and dTmp2 , that is, interpolate dTmp1 according to g1 and g2 in Figure 1, and interpolate dTmp2 according to g3 and g4 ( to obtain dTmp1, dTmp2 pixel values ​​at two positions ) , which uses its gradient direction, which is why the Canny algorithm needs to solve the gradient direction matrix Thita ( the second step of the algorithm ) .

After the non-maximum value suppression is completed, a binary image will be obtained. The gray value of the non-edge points are all 0. The gray value of the local gray maximum value point that may be the edge can be set to 128 or others.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324819625&siteId=291194637