Organized in Zhihu: Non-maximum suppression in canny
and csdn: canny operator 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.
(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 in order 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 .
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 ) .
完成非极大值抑制后,会得到一个二值图像,非边缘的点灰度值均为0,可能为边缘的局部灰度极大值点可设置其灰度为128或者其他。