Sobel Edge Detection Algorithm with Adaptive Threshold based on Improved Genetic Algorithm for Image Processing

—In this paper, a novel adaptive threshold Sobel edge detection algorithm based on the improved genetic algorithm is proposed to detect edges. Because of the influence of external factors in actual detection process, the result of detection is often not accurate enough when the configured threshold of the target image is far away from the real threshold. Different thresholds of images are calculated by improved genetic algorithm for different images. The calculated threshold is used in edge detection. The experimental results show that the image processed by the improved algorithm has stronger edge continuity. It is shown that proposed algorithm has a better detection effect and applicability than the traditional Sobel algorithm.

For different edge detection algorithms, many optimization strategies have been proposed to obtain better detection effects. Image edge detection is greatly affected by noise. In the process of Sobel edge detection, the mean filtering method of median filtering is commonly used to remove noise. However, this method has a general effect of removing salt and pepper noise. To better remove noise, soft threshold wavelet denoising is applied to Sobel operator edge detection [4]. In order to meet the real-time requirements of PC ports, an eight-direction adaptive threshold Sobel operator edge detection algorithm is proposed, which"s mapping is realized on FPGA [5]. The adaptive threshold edge detection algorithm based on fuzzy divergence uses adaptive threshold to detect the target image [6].
With the rise of artificial intelligence, the application of artificial intelligence algorithms in the field of image processing has become a hot topic. In aerospace, remote sensing, medical and other high-end industries, the accuracy of image processing is required to be high. In view of this situation, artificial intelligence algorithm has great advantages. In addition, deep learning algorithm and neural network algorithm are applied in edge detection [7][8][9]. In the processing of complex images, artificial intelligence algorithm has advantages. However, the artificial intelligence algorithm has the disadvantages of large amount of calculation, long time for edge detection and the need to train the algorithm in advance when detecting the edge of specific image. In practical applications, the edge detection algorithm is required to have the characteristics of fast response, low hardware requirements, wide range of detection targets and so on.
The research of traditional image edge detection is still widely concerned. For the limited edge extraction of Sobel operator in horizontal and vertical directions, the quantum of non-maximum suppression and double threshold technology are adopted to improve it [10]. For the noise problem in Sobel operator edge detection, median filter algorithm, mean filter algorithm, weighted kernel norm minimization image denoising algorithm and traditional Sobel algorithm are usually used to achieve better detection effect [11]. However, the Sobel edge detection algorithm still needs to manually set the threshold [12].
To solve this problem, an adaptive threshold edge detection algorithm based on improved genetic algorithm is proposed. According to different target images, different thresholds are calculated and used for edge detection to avoid the problem of low accuracy of edge detection caused by improper manual threshold setting.

II. PRINCIPLE OF SOBEL EDGE DETECTION
As a common edge detection algorithm, Sobel operator combines Gaussian smoothing and differentiation to calculate the gradient value of image brightness function. The main method is to make the weighted difference between the gray values of the upper, lower, left and right fields of the target pixels, and then smooth the image. The greater the weight close to the target pixel, the greater the impact on the target during convolution [13][14]. The steps of the Sobel operator to determine the image edge are as follows: www.ijacsa.thesai.org Step 1: Horizontal operator x Sobel and vertical operator y Sobel are used to convolute the target image. The horizontal and vertical operators of Sobel algorithm are described as follows: Step 2: The convolution value of Sobel operator in x and y directions is calculated by: ( 1, 1) Step 3: By comparing with the preset threshold, it is determined that the point is an image edge when the value of the point is greater than the threshold, otherwise is not.
The classic Sobel edge detection operator uses the gray weighting algorithm of the top, bottom, left and right of the target pixel to determine whether it is an edge pixel. This method can not only extract the edge of the target image but also smooth the noise. However, the effect is not very well when the edge extraction is fine or the image threshold is not set properly.

III. IMPROVED SOBEL EDGE DETECTION ALGORITHM
If the threshold setting in the traditional Sobel operator edge detection algorithm is unreasonable, the accuracy of edge detection is not high. However, the threshold setting is manual, and different images need to be set according to experience. In this way, a large number of pictures cannot be processed automatically. In this paper, adaptive genetic algorithm and traditional Sobel edge detection algorithm are combined. Different thresholds of images are calculated by genetic algorithm for different images. The calculated threshold is used in edge detection. The process of the improved Sobel edge detection algorithm is shown in Fig. 1.

A. Improved Sobel Edge Detection Algorithm
The genetic algorithm is a computational model of the biological evolution process that simulates for the natural selection and genetic mechanism of Darwin's biological evolution theory. It is the method to search the optimal solution by simulating the natural evolution process. Genetic algorithm was proposed by Professor Holland firstly. It is a general solution to solve the search algorithm, especially suitable for the calculation of the optimal solution. The genetic algorithm has been widely used in many fields such as production scheduling, automatic control, image processing, machine learning and so on [15][16][17].
The basic operation of the genetic algorithm includes three basic operators: selection, crossover, and mutation. The genetic operation of an individual population is carried out under random disturbance, so the migration process of the optimal solution is also random. It should be emphasized that this random migration is different from the traditional random search, and the search of genetic operation is efficient and directional. The specific manifestations of genetic operation are as follows:

1) Selection:
The operation of choosing high-quality individuals in the population and eliminating low-quality individuals is called selection. The purpose of the selection operation is to transfer the genes of high-quality individuals to the next generation. The criterion of selection is based on an appropriate individual fitness assessment. At present, the commonly used fitness evaluation methods include the roulette selection method, fitness proportion method, random traversal sampling method, local selection method and others. And roulette selection method is used most widely.
2) Crossover: In the process of biological evolution, genetic recombination plays a key role. Similarly, in the genetic algorithm, crossover operator operation is the core of the whole genetic algorithm. Cross operation means recombing part structure of two-parent individuals to obtain a new individual through cross replacement and achieving the purpose of recombining the desired gene. The crossing modes include single-point crossing and multi-point crossing and uniform crossing. The most common is single-point crossing.
3) Mutation: The operation of the mutation operator in the genetic algorithm is to change a certain gene of an individual and to achieve the purpose of changing individual genes. The mutation operation not only increases the diversity of the population and prevents premature convergence, but also enhances the local search ability of the genetic algorithm and accelerates the convergence. Common mutation methods include real-valued mutation and binary mutation.
The above operations are the basic operations of the genetic algorithm. The effect of the genetic algorithm is largely related to the population size, iteration times, crossover probability and mutation probability set by the three genetic operators. In this term, this paper adopts an adaptive genetic algorithm compared with the traditional genetic algorithm. By calculating individual fitness, the algorithm adopts different crossover and mutation probabilities for individuals with different fitness, to increase the individual diversity of the population and achieve the purpose of rapid global convergence. The specific improvement details are as follows.
where c P is the probability of crossover, and c f is the individual with greater fitness in the two individuals of the parent generation. max f and min f are the maximum and minimum fitness of the individual in the population. 1 2 3 ,, k k k are constants between 0 and 1, and 23 kk  .
2) Adaptive mutation probability: Mutation operation is an indispensable link in genetic algorithm, which mainly ensures the diversity of population genes. Through the combined action of crossover and mutation, the population will rapidly converge towards the optimal solution. In the mutation operation, the mutation probability is used to represent the intensity of mutation. Usually, a smaller value is required to prevent the mutation operation from misoperating the genes of excellent individuals in the population. In order to prevent the premature convergence of the population caused by the misoperation of the mutation operation on the excellent individuals, the adaptive improvement is made in this paper. The mathematical principle is shown: where m P is the mutation probability, c f is the one with greater adaptability among parents, and max f , min f are the maximum fitness and minimum fitness of the population. 456 ,, f f f are constants between 0 and 1, and 56 kk  . Through the adaptive improvement of crossover operation and mutation operation. The flow of the adaptive genetic algorithm is shown in Fig. 2.

B. The Principle of Calculating the Optimal Threshold by Genetic Algorithm
In the process of using genetic algorithm to calculate the image threshold, the maximum inter class variance of the image is used as the best fitness function to calculate the threshold.
If the number of pixels with gray i is i m , the total number of image pixels is: Normalize the histogram of the image to obtain the probability distribution of the gray level as follow: The variance between the two classes is:  is maximum, t is the optimal threshold.

C. Adaptive Threshold Sobel Edge Detection Algorithm
The traditional Sobel needs to manually set the image threshold. When the manually set threshold is close to the real image threshold, the effect of image edge detection is preferably. However, in practice, image acquisition is greatly affected by external factors such as illumination, which makes the threshold values of different images vary greatly. The effect of traditional Sobel operator in image edge detection with different thresholds is not ideal.
To solve this problem, this paper combines the genetic algorithm with the traditional Sobel edge detection algorithm and proposes an adaptive threshold Sobel edge detection algorithm. Setting different thresholds for different images avoids the influence of external factors on image segmentation and has a better effect. The implementation steps of the algorithm are as follows: 1) Import the target image, determine the parameter set according to the actual problem, encode the parameter set, set the initial parameters, etc.
2) The population individuals are selected, crossed, and mutated adaptively and iterated to the optimal individuals, which means calculating the threshold of the image.
3) Pass the threshold in step 2) to the classical Sobel edge detection algorithm to avoid manually setting the threshold.
4) Compare the threshold with the convolution value calculated by the convolution operator to judge the image edge.

5)
Complete edge detection and output the target image.
The above is the whole process of the adaptive threshold Sobel edge detection algorithm.

IV. EXPERIMENTAL RESULTS AND ANALYSIS
In this section, we present the results by the proposed algorithm and the traditional Sobel algorithm.

A. Initial Parameter Setting
Take the person image shown in Fig. 6(a) as the test image to test the edge detection process of the algorithm. The initial parameter settings are shown in Table I.
The three groups of initial parameters in Table I are tested respectively to obtain the best fitness curve and the best threshold curve under the three groups of parameters. The best fitness curve and the best threshold curve of the three groups of parameters are shown in Fig. 3, Fig. 4   In group 1, the optimal threshold is 118. In group 2, the optimal threshold is 120. In group 3, the optimal threshold is 118. In the group 2 of data, the optimal solution will converge in advance due to the small number of populations and iterations. The calculation of image threshold is inaccurate. Although the image threshold calculation of the group 3 of data is accurate, the amount of calculation increases and resources are wasted due to the excessive parameter setting. Comprehensive comparison shows that the group 1 of data not only ensures the accuracy of calculation, but also has a moderate amount of calculation. Therefore, in the following image processing, the group 1 of parameters are used as the original parameters to calculate the threshold of the image.

B. Edge Detection Process
According to the initial parameters of group 1, the threshold value of the image in Fig. 6(a) is calculated, which is 118. Before edge detection of the target image, the image needs to be processed. First, the grayscale image shown in Fig. 6(b) is obtained by grayscale processing of Fig. 6(a). In order to make the experimental process closer to the real detection process, random salt and pepper noise is added to the gray image to simulate the random noise in the process of image acquisition. The noise diagram shown in Fig. 6(c) is obtained. After the above preparations are completed, the threshold value detected in Section 4A is transferred to Sobel operator to detect the edge of the target image. Finally, the edge detection effect shown in Fig. 6(d) is obtained. As shown in Fig. 6, the algorithm in this paper has a good effect on the edge detection of the target in the noisy environment. The contour of edge detection is clear. The image details are complete. The image information is completely saved, which can meet the further processing of the target image. At the same time, the algorithm overcomes the problem that the edge detection effect is not ideal due to the large gap between the image threshold and the set threshold. The threshold of the target image is calculated by genetic algorithm. The calculated threshold value is then transferred to the Sobel operator to replace the manually set threshold value. Finally, the purpose of adaptive threshold edge detection is achieved.

C. Analysis of Experimental Results
In order to show the edge detection effect of the algorithm under different images, this paper uses three examples to compare the algorithm with the traditional Sobel algorithm with different thresholds. The traditional Sobel operator setting threshold and adaptive threshold of each image are shown in Table II. The comparison diagram of different thresholds of the three examples is shown in Fig. 7, Fig. 8, and Fig. 9.

V. CONCLUSIONS
In this paper, Sobel edge detection algorithm based on the genetic algorithm is proposed. Compared with the traditional Sobel algorithm, it does not need to set the threshold manually, which avoids the poor detection effect caused by different image thresholds. This algorithm has great improvement The image edge is located accurately. The image details are well preserved. It can adapt to images with different thresholds and has great practical application value.