The Application Study on the Improved Canny Algorithm for Edge Detection in Strain Gauge Image

In order to realize automatic cutting of strain gauge diaphragm, it is needed to detect and identify strain gauge edge. Though classic canny algorithm can detect the edge of strain gauge, it has such problems as low accuracy, being easily influenced by light, random noise. This paper proposes an improved canny algorithm, replacing Gauss filtering of classic canny algorithm with median filtering, improving gradient magnitude calculation method, and selecting threshold with iteration. Compared to classic canny algorithm the method can improve the ability to resist random noise while detecting strain gauge edge more accurately. Application of the method to strain gauge edge detection will lay foundation for realization of strain gauge automatic cutting.


Introduction
Resistance strain gauge is a strain measuring device used most widely and most effective in strain measuring technology of engineering structure.Resistance strain type weighing sensor made of various resistance strain gauge plays vital role in electronic industry.The diaphragm of strain meter in strain gauge production process is 115mm long, 100mm wide, with total 150 strain units.Currently domestic producers still adopt manual cutting, with lower quality, yield and production efficiency than automatic cutting, and strain gauge image edge detection is the key technology that needs to be resolved for strain meter diaphragm automatic cutting.Recently as mathematical theory and AI develop, many new modern edge detection methods emerge, Canny approximately replaces optimal algorithm with first derivative of Gauss function, proposing Canny algorithm, empirically testing effectiveness of the algorithm in detection, positioning and single edge response [1][2][3].So far, among existing edge detection algorithms, Canny edge detection is still the most important detection algorithm [4].But classic canny algorithm has some flaws, such as the problem of response to random noise and fuzzy image boundary.This paper uses median filtering to detect strain gauge image, increasing anti-noise capacity of canny algorithm, meanwhile selects appropriate threshold to eliminate weak edge, increasing accuracy of edge detection.

Canny Principle and realization procedure of Canny algorithm
Classic edge detection algorithm realizes edge positioning based on original image, by solving differential of location with obvious gray variation in the image, in brief, uses gradient variation between brightness and darkness.Its biggest advantage is simplicity, and effectiveness.Canny finds that optimal algorithm can be approximately replaced with first derivative of Gaussian function, so he proposes Canny algorithm based on it, and empirically tests the effectiveness of the algorithm in detection, positioning and single edge response.Realization of Canny algorithm mainly includes the following procedures: (1) Gray processing of source image Canny algorithm mostly processes gray image, processing color image needs gray processing of image.Gray processing of color gram is to sample red, green, blue channel of image and take weighed mean of sampled value.In terms of RGB format, gray processing often uses the following methods, as shown in equation 1 and 2.

Gray = (R+G+B)/3
(1) Gray=0.299R+0.587G+0.114B; (2) Where parameters in equation 1 are set mainly considering physical characteristics of human eyes, the color image of other format can also be transformed to RGB format according to corresponding relation before gray processing.
(2) Gaussian filtering processing of image Filtering operation of image can be achieved by two differential weighing processing of 2 one-dimensional Gaussian cores or one convolution of 1 two-dimensional Gaussian core.
Realization of Gaussian core MATEC Web of Conferences 128, 01017 (2017) Equation 3 is discrete form of one-dimensional Gaussian function, where is the variance of the function, when the parameter is determined, the one-dimensional core vector is known.
(4) Equation 4 is discrete form of two-dimensional Gaussian function, where is the variance of the function, when the parameter is determined, the two-dimensional core vector is known.
Gaussian filtering operation of image is essentially a weighing mean operation following specific rules based on gray value of pixel points to be filtered and every point within neighbourhood, which is very useful to filter out high frequency noise mixed in the image.
(3) Calculation of gradient amplitude and direction Use first differential algorithm to solve partial derivatives of center pixel point in X and Y direction G � and G � respectively, and the amplitude and direction of gradient can be obtained, its expressions of first partial derivative, gradient amplitude and direction are shown in equation 5, 6, 7 and 8.
In equation 5, 6, 7 and 8, f�i, j� is center pixel point, G � and G � are first partial derivatives of center pixel point, G is its gradient amplitude, is direction derivative.
(4) Non-maximum suppression of gradient amplitude Only global gradient is not enough to determine edge, so in order to determine edge, the point with max local gradient must be retained, and use the direction of gradient to suppress non-maximum, discretize gradient angle into one of four sections of circumference, so as to use a 3 x 3 window to conduct suppression operation.Mark numbers of 4 sections are 0 to 3, corresponding to 4 possible combinations of a 3 x 3 domain, at every point, the center pixel of domain M[x,y] compares with 2 pixels along gradient line.If the gradient value of M[x,y] is not greater than gradient values of two neighbouring pixels, then let M[x,y]=0.
After maximum suppression of image, we will obtain a binary image, but the image still contains many false edges resulting from noise or other causes, so the image needs further processing.
(5) Edge detection and connection of dual-threshold algorithm The typical method to reduce number of false edge is to use a threshold to N�i, j�, giving zero value to all values less than the threshold.Select a threshold using dualthreshold algorithm.Dual-threshold algorithm applies 2 thresholds T � and T � to non-maximum suppression image, and T � � 2T � , so 2 threshold edge image N � �i, j� and N � �i, j� are obtained.Because N � �i, j� is obtained using higher threshold, it contains very few false edge, but contains discontinuity (non-closure) [5].Dual-threshold algorithm will connect edges to contour in N � �i, j�, when arriving at end points of the contour, the algorithm will locate the edge able to connect the contour at the location of 8 neighbouring points of N � �i, j�, as such, the algorithm continuously collects edge in N � �i, j� till connecting with N � �i, j� .when connecting edges, use array to simulate realization of queue, conducting 8 connected domain search.

Improvement of Canny edge detection algorithm 3.1 Improve image filtering method
Median filtering is a nonlinear smoothing technique, setting gray value of every pixel point as mid-value of gray value of all pixel points in a neighbourhood window of the point.Median filtering is based on sequence statistical theory, effectively suppressing noise [6].The paper uses 3 x 3 two-dimensional rectangle filter.Its operating procedure is: first, rank pixel value in neighbourhood according to gray value.Then, take pixel mid-value of ranked sequence as output mid-value.Finally, compare gray value of surrounding pixel with output mid-value, modify the pixel value with greater difference to a value close to surrounding pixels to realize elimination of noise point [7].In traditional median filtering, every pixel in filtering zone influences the result equally, without considering the important factor of distance between them and the center, so the proposed median filtering with weighing value distributes an independent weighing value for every location in filtering zone, and distribution of weighing value is decided by the matrix W�i, j� ∈ Ｎ .During filtering calculation, every pixel value I�� � i, � � j� is inserted in extended pixel vector, times of insertion id its weighing value W�i, j�, extended pixel vector is shown in equation 9.
� � �� � ,���, � ��� � (9) Where, length Then rank the pixel vector, with a pixel as the center, select a 3 x 3 two-dimensional rectangle neighbourhood, rank the pixel vector according to gray value of every pixel in the neighbourhood.Calculate mid-value y according to equation 10, next further conduct median filtering processing according to mid-value.
Where, y is mid-value, f � ,���, f � is pixel points in 3 x 3 square neighbourhood, x � is the value of the array after pixel points in 3 x 3 square neighbourhood are ranked, i is the location of every value in the array, n is the length of the array.

Improved gradient amplitude calculation method EITCE 2017
Canny algorithm calculates gradient amplitude by solving finite difference in 2 x 2 neighbourhood, considering sensitivity of the method to noise, it easily detects false edge, missing real edge.The improved method uses first partial derivative within a 3 x 3 neighbourhood to solve gradient amplitude and direction [8].First calculate the first partial derivative in the direction of x, y, 45 ° and 135 °, as shown in equation 11, 12, 13 and 14.X：F � �x, y� � I�x � 1, y� � I�x � 1, y� (11) Y：� � ��, �� � ���, � � 1� � ���, � � 1� (12) Then, use partial derivatives in the four directions to solve the difference in vertical and horizontal direction, as shown in equation 15, 16: (16) Finally use equation 17 and 18 to solve gradient amplitude g and gradient direction .

Selection of image segmentation threshold
Threshold segmentation, in brief, is to segment the target of image from background with threshold, and require to minimize the probability of improper segmentation of target from background.When dealing with practical problem, however, due to adverse influence of noise and other inevitable factors on selection of threshold, it is very difficult to determine a threshold meeting requirement.Using iteration algorithm to determine threshold, not only reduces interference of noise and other factors with selection of threshold, but also determines optimal threshold more easily [9].
Mean value T of minimum Z ��� and maximum Z ��� of gray value is obtained through histogram statistics and is used as initial threshold, then use the T to divide gray value -part H � above T and part H � below H, solve mean value TL of H � , then again solve mean value of T � and T � as threshold, and the threshold is new threshold obtained after our first iteration, compare obtained new threshold with the initial threshold.It their value is the same or their difference meets the condition we set, the iteration ends, T � and T � are required optimal high, low threshold.If condition is not met, use the threshold obtained this time to divide all gray value again, continue the process of iteration till new threshold meets requirement [10].New threshold calculated through multiple iteration will be much better than initial threshold, minimizing probability of improper segmentation of image.Specific procedure of iteration algorithm is as follows: (1) Make statistic of histogram of image, use equation 19, 20 to calculate initial threshold T of image Where K is times of iteration, Z ��� represents max gray value, Z ��� represents min gray value. ( Where f�i, j� is gray value of pixel point �i, j�, N � �i, j�, N � �i, j� meet conditions of equation 25, 26 respectively.1, it can be found that compared to edge characteristics detected by classic Canny algorithm, threshold obtaining method improved algorithm detect more real edges when automatically selecting threshold, and filtering and gradient solution improved algorithm detects most complete edge characteristics among three algorithms when selecting very good threshold.2. When adding Gaussian noise, compare detection results of Fig. 2, it can be found that the algorithm using Gaussian filtering almost filter out all false edges produced by noise, but it also filters out many real edges, especially when using traditional algorithm of manually setting threshold, and the algorithm using median filtering keeps most real edges though, it also keeps many false edges resulting from noise.

Conclusion
There are many image edge detection methods, but precision and time of strain gauge cutting need to be guaranteed during strain gauge edge detection.Aiming at these requirements, based on classic canny algorithm, during canny algorithm edge detection processing, the design optimizes Gaussian filtering processing and threshold selection.Experimental result shows that the optimization method proposed in the paper has obvious effect on increasing accuracy of strain gauge edge detection and anti-noise capability, as well as certain reference value for application of strain gauge visual detection cutting.

( 4 )
Calculate mean value of T � and T � as new threshold TT, as shown in equation 27.If TT and initial threshold have same value or meet the condition we set, then iteration is completed, if TT obtained this time fails to meet requirement, then continue iteration till TT meeting requirement is found.(6)Iteration completes, use the result of calculation TT -T � and T � meeting condition as optimal high, low threshold for detection.4Result of strain gauge image edge detection 4.1 Experimental test of edge detection methodThe key for Canny algorithm to detect image edge is selection of Gaussian filtering function and threshold.Fig. 1 a is the image of original strain gauge, Fig. 1 b is the image of edge detected by classic canny algorithm, Fig. 1 c Image of filtering and gradient solution improved Canny algorithm edge detection, Fig. 1 d Image of threshold obtaining method improved Canny algorithm edge detection To test processing effect of improved canny algorithm on Gaussian noise, add Gaussian noise to strain gauge original image.Fig. 2 a is Gaussian noise added original image, Fig. 2 b is classic canny algorithm detected edge image, Fig. 2 c is filtering and gradient amplitude solution improved canny algorithm detected edge image, Fig. 2 d is threshold improved canny algorithm detected edge image.

Figure 2 .
Figure 2. Result of edge detection when adding Gaussian noise 2) Divide image into part H � above T and part H � below H, as shown in equation 21, 22. Calculate gray mean value T � ,T � of H � and H � , as show by equation 23, 24.