Research on edge detection algorithm based on improved sobel operator

. In order to solve the shortcomings of traditional detection operator, such as low accuracy of image edge location and rough edge extracted, an improved edge detection algorithm based on Sobel operator is proposed. Firstly, in the aspect of the accuracy of edge detection, the direction template is increased from two directions of horizontal and vertical to eight directions; secondly, in terms of the rough edge extracted and the noise sensitivity, combined with the operation of mathematical morphology, the edge can be refined, and at the same time, some part of the noise can be suppressed. The experiment results show that the improved edge detection algorithm has a better accuracy in image positioning, and a certain ability to suppress noise. Finally, the detected image edge of the image is more delicate and clear than the traditional Sobel operator.


Introduction
In the 20th century, digital image processing technology began to appear and developed rapidly. Its application is very extensive, involving military science, agriculture, industry, medical and health [1] and other fields. The edge of digital image exists everywhere in the image, which contains a lot of information and plays a very important role in the postprocessing of the image, so the edge detection of the image also develops rapidly. The edge of the image can be said to be the gray segmentation line between different regions with different gray values, representing the end of one region and the beginning of another new region. The edge exists in the part where the gray values of the image changes sharply [2], and it can be used as the dividing line between the target object and the background in the image.
The commonly used first-order differential operators are roberts operator, Sobel operator and Prewitt operator, and the second-order differential operators are Laplacian operator and LOG operator. These traditional algorithms are simple in operation and fast in running, but they also have defects such as many detected edge breakpoints, low positioning accuracy and sensitivity to noise. Therefore, many new algorithms have been proposed in recent years, such as the edge detection algorithm based on neural network and morphology, etc [3,4].
These algorithms have good detection effect, but the algorithm is complex and the implementation speed is slow. For traditional Sobel operator, its calculation is simple, running quickly, but there are defects. this paper is aiming at the shortcomings of the traditional Sobel detection operator, proposing an improved algorithm, which extends the operator template to eight directions, and then refines the obtained edge by morphological operation. So compared with the traditional Sobel detection operator, it has better improvements in the thickness of the edge, positioning accuracy and so on.

Basic principles of traditional sobel operator
At the edge of the image, the pixel value changes violently and the gradient amplitude is large. Therefore, the gradient image of an image can be used to determine whether it has the edge we want and the location of the edge we want. Let an image be h(x,y), and the neighborhood of an image is shown in Fig.1. The central pixel is (x,y), and the gradient [5] at the pixel (x,y) can be obtained as Eq .1. It is a vector with a size and direction. Where, the magnitude of the gradient amplitude can be obtained from Eq .2 and can be obtained from Eq .3 [6] for simple calculation. The gradient direction can be obtained from Eq .4: h(x,y) = h x (x,y) + h y (x,y) The calculation of partial derivative of the gradient above is large. In practical calculation, the template is used to approximate the gradient by convolution. The traditional Sobel operator is an edge detection operator based on the first derivative, it has 3 3 edge detection templates in two directions, which detect the horizontal and vertical edges respectively. The templates are shown in Fig.2.

Fig. 2. Sobel operator template.
When Sobel operator is used to detect the edge of an image, the horizontal and vertical operator templates in Fig.2 are respectively used to perform convolution operation on each pixel in the image, as shown in Eq.5 and Eq.6, and then the gradient value at each pixel point in the image can be obtained from Eq.3. h x x,y =h x+1,y-1 +2h x+1,y +h(x+1,y+1) h y x,y =h x-1,y+1 +2h x,y+1 +h x+1,y+1

Sobel operator detection edge steps
According to the gradient image of an image described in 2.1, the general steps of traditional Sobel operator to detect image edges can be summarized: (1) traverse the horizontal and vertical templates in Fig.2 from top to bottom and from left to right respectively, for each pixel in the image. The desired target pixel is corresponding to the center pixel of the template, and the convolution values hx, hy are obtained from Eq.5 and Eq.6.
(2) The gradient value |grad[h(x,y)]| at each pixel can be obtained by substituting the convolution values hx, hy into Eq.3,and then assign this value to the pixel in the center of the corresponding template in the image as a new pixel value. In this way, a gradient image can be obtained by calculating the new gray value of each pixel in the image successively.
(3) set a threshold Th, and compare each pixel value in the newly obtained gradient image with the threshold Th, as shown in Eq.7: If the gray value is greater than or equal to the threshold value Th, then this pixel point is the edge point. If less than the threshold value Th, the pixel point is not an edge point and is set to 0. In this way, the identified edge points are connected together to be the image edges detected by the Sobel operator.

The basic principle of improved sobel operator
Traditional Sobel operator is simple in calculation and fast in implementation. However, there are only horizontal and vertical detection templates. the detected image edge positioning accuracy is not high, and the edge is relatively thick. In order to improve the edge positioning accuracy, the traditional Sobel operator detection template can be extended from horizontal and vertical directions to eight directions. Although there are many edge directions of an image, it can be determined that there will be at least 360 ° direction. The original template with 0 ° and 90 ° direction is now added with 45 °, 135 °, 180 °, 225 °, 270 ° and 315 ° direction templates [7]. The eight direction templates are shown in Fig.3.
According to the principle of traditional Sobel operator's two-direction template detection of image edges, the improved eight-direction template detection of image edges can be obtained. For an image neighborhood of an image, as shown in Fig.1, the gradient value obtained by the operator template of 135 ° direction after convolving a certain point of the image is as shown in Eq.8: h 135° x,y =h x,y-1 +2h x+1,y-1 +h(x+1,y Like the algorithm in the above formula, after obtaining the gradient value in each direction of the image, the new gray value and direction of the target pixel can be determined by judging the maximum value, and then the image edge can be obtained by discriminating the edge point through the threshold value.

Mathematical morphological operation
Mathematical morphology operation [8] is to select appropriate structural elements to act on the image, which are to be processed and perform some operations to meet our requirements. Expansion and corrosion are the two most basic operations in morphology. The corrosion operation is used to eliminate the small connected area and the small particle noise in the image. The expansion operation is used to connect adjacent objects and fill the holes in the objects. If the image to be processed is X and the structural element is Z, the corrosion and expansion operations can be denoted as: Eq.9 indicates that the set obtained by using Z to corrode X is the set of the origin position of Z when Z is completely included in X.
Eq.10 indicates that any point in X can be expanded to Z+ X by using Z to expand X. The closed operation is to inflate image X first, and then corrode the obtained results, so that small gaps can be connected and holes can be filled. And the open operation is to corrode the image X first, and then inflate the obtained result, which can remove the narrow connection part and the small protrusion part. They are as shown in Eq.11:

Improved sobel operator edge detection steps
Referring to the traditional Sobel operator, combining the eight direction templates and mathematical morphology operation of the improved Sobel operator, the improved algorithm steps can be proposed: (1) each of the eight direction templates in Fig.3 is used to the operation of convolution in a pending image pixel by pixel from left to right and from top to bottom; (2) the maximum value of the result obtained by convolving operation is used to replace the pixel value of the target pixel point and become a new gray value, and the template direction corresponding to the maximum value is the edge gradient direction of the target pixel point, so the gradient image can be obtained; (3) the gradient image is processed based on the global threshold Th. If the pixel value of the gradient image is less than the threshold Th, the pixel value is set to 0; if it is greater than or equal to the threshold Th, the pixel value is set to 255; (4) the edge of the image obtained by the above three steps is relatively thick. It can be refined by combining the expansion, corrosion, opening and closing operations in mathematical morphology operation, and finally the edge of the image can be obtained.

Simulation results
It can be seen from the detected edge image that the edge detected by several traditional operators is not as good as the image edge continuity detected by the algorithm in this paper. Fig.4 shows several traditional operators of liftingbody image as well as the edge image detected by the algorithm in this paper. The traditional Sobel operator has some anti-noise ability, but the detection edge continuity is not good and there are many breakpoints. Prewitt operator has many false edges, wide detected edges and poor continuity.LOG operator has a certain anti-noise ability, but the detected edge continuity is not good. The introduction of gaussian filter will cause undue smoothness to the image and lose some edge points. The edge extracted by Canny operator is better in continuity and more detailed than the previous operators, but there is still edge breakpoints. The algorithm in this paper detects the edge of the image in eight directions and improves the positioning accuracy. Compared with that of traditional operators, some noise is diluted, and the overall edge contour is clear, continuous and hierarchical, and the detected edge is exquisite. Based on the traditional Sobel operator, this paper proposes an improved Sobel algorithm, aiming at the disadvantages of low edge positioning accuracy and thick edge. This algorithm adopts eight-direction template, sets global threshold to detect edge points, which is simple and convenient, and uses morphological algorithm to refine edge. Experimental results show that the final image edge positioning accuracy has been improved, and the edge is relatively complete, clear and fine and smooth. Although the improved Sobel algorithm in this paper makes up for the shortcomings of the traditional Sobel operator to some extent, the extracted edge has good continuity, the positioning accuracy has been improved to a certain extent, and the edge is fine, but there are still some cases of missing edge points, and the global threshold is used to identify edge points, although simple and general, but not targeted, which need further exploration.