Research on the combination of improved Sobel operator and ant colony algorithm for defect detection
MATEC Web of Conferences 336, 01009 (2021)
CSCNS2020
https://doi.org/10.1051/matecconf/202133601009
Research on the combination of improved Sobel
operator and ant colony algorithm for defect
detection
Yilu Zhou *, and Xiaojin Fu
Shanghai Dianji University, Shanghai, China
Abstract. There are many aspects in the defect detection system. Any
deviation in any link will affect the accuracy of the final detection, and edge
detection is very important in the image preprocessing stage. In this paper,
a new edge detection algorithm is proposed. Firstly, the improved Sobel
operator is used to detect the image contour, and then the position of the
contour is taken as the initial position of ant colony algorithm. The
experimental results show that the algorithm can extract the contour with
uniform thickness and length from the original image collected by the
industrial camera, and the running time of the algorithm is almost the same
as that of the traditional ant colony algorithm, thus providing more accurate
data for the defect detection of products in the later stage.
1 Introduction
Nowadays, with the rapid development of digital image processing and computer vision
technology, more and more researchers use the camera as the sensing sensor to detect product
defects. This is mainly because the original ultrasonic or infrared sensors have limited
information and poor robustness, and the vision system can make up for these shortcomings.
Before using industrial camera to detect defects, the most important thing is to extract the
product edge completely. In reference [1-2], the traditional Sobel algorithm is improved,
from the original horizontal and vertical templates to four direction templates, the integrity
of the edge has been improved to a certain extent. In reference [3], the adaptive OSTU is used
the algorithm is used to detect the edge of ship target, and the segmentation effect of binary
target is better, but it is affected by uneven illumination and other factors. In the traditional
ant colony algorithm, he initial position of ants is randomly distributed. In reference [4], the
ant colony algorithm is optimized, and the initial position of the ant is placed near the edge,
which can significantly improve the running time of the algorithm, but there is no clear
explanation on how to determine the initial position. In this paper, Sobel operator is used to
determine the specific position of the edge, and then the ant colony algorithm is used for edge
detection. Finally, experiments show that this method can effectively extract the complete
edge contour.
*
Corresponding author:
© The Authors, published by EDP Sciences. This is an open access article distributed under the terms of the Creative Commons
Attribution License 4.0 (http://creativecommons.org/licenses/by/4.0/).
MATEC Web of Conferences 336, 01009 (2021)
CSCNS2020
https://doi.org/10.1051/matecconf/202133601009
2 Analysis of Sobel operator edge detection
There are many algorithms for edge detection, each has its own advantages and disadvantages,
and Sobel operator is the most commonly used edge detection operator in one step algorithm.
2.1 Traditional Sobel edge detection algorithm
The traditional Sobel operator uses two templates in horizontal and vertical directions for
edge detection. It takes a short time to process the image because of the simple formula. The
operator contains two groups of 3 * 3 matrices, and the convolution template is shown in
Figure 1:
Fig. 1 Convolution template of Sobel operator.
2.2 Improved Sobel edge detection algorithm
Sobel operator approximately estimates the edge of the image by calculating the gradient of
image brightness, so only considering the horizontal direction and vertical direction will
make the detected edge image lose some details. Many scholars propose to increase the
direction of 45 ° and 135 ° to make the algorithm more accurate for the extraction of oblique
edge features. The improved convolution templates in four directions are shown in Figure 2:
Fig. 2 Improved convolution template of Sobel operator.
After each pixel of the image is convoluted with the convolution template, the pixel value
corresponding to the center of the convolution template is replaced by the maximum value
of the convolution result, and all the pixels that have been convoluted are merged into a new
gray image. the most important thing to extract the contour in edge detection is to determine
the value of threshold T. the threshold of Sobel operator refers to the 𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔𝑔 = 𝑓𝑓𝑓𝑓𝑥𝑥𝑥𝑥 +
𝑓𝑓𝑓𝑓𝑦𝑦𝑦𝑦 obtained from the partial derivative calculation of each pixel, and the edge is obtained by
thresholding the grad. Pixels larger than the threshold will be displayed, and smaller than the
threshold will no longer be displayed, so the selection of T will determine whether the image
will lose some edges or leave more noise. Because the weight is added to Sobel operator, the
result will result in a wider edge.
2
MATEC Web of Conferences 336, 01009 (2021)
CSCNS2020
https://doi.org/10.1051/matecconf/202133601009
Therefore, in order to get a better threshold T, Otsu can be used to find out the gray
histogram of the image, and then use this threshold to demarcate the respective variances on
both sides of the boundary, and then calculate the absolute value of the difference between
the two variances. When the absolute value is the maximum, the boundary gray level is the
threshold gray level. The variance formula of foreground and background image is:
𝑔𝑔𝑔𝑔 = 𝜔𝜔𝜔𝜔0 ∗ (𝜇𝜇𝜇𝜇0 − 𝜇𝜇𝜇𝜇)2 + 𝜔𝜔𝜔𝜔1 ∗ (𝜇𝜇𝜇𝜇1 − 𝜇𝜇𝜇𝜇)2 = 𝜔𝜔𝜔𝜔0 ∗ 𝜔𝜔𝜔𝜔0 ∗ (𝜇𝜇𝜇𝜇0 − 𝜇𝜇𝜇𝜇1 )2
(1)
The proportion of foreground points to the image is 𝜔𝜔𝜔𝜔0 , and the average gray level is 𝜇𝜇𝜇𝜇0 ;
the proportion of background points to the image is 𝜔𝜔𝜔𝜔1 , the average gray level is 𝜇𝜇𝜇𝜇1 , the
total average gray level of the image is 𝜇𝜇𝜇𝜇, and the inter class variance is g. Finally, the
threshold T with the largest variance between classes can be obtained by traversing. Although
the improved Sobel operator can effectively improve the effect of edge detection, it is still
unable to extract continuous and complete edges.
3 Using ant colony algorithm to optimize
Ant colony algorithm (ACO) is a probabilistic algorithm for finding the optimal path in
graphs. It was proposed by Dorigo M. in 1991[5]. After setting the initial point, each ant
begins to search for food in different places, and releases pheromones in the surrounding
environment. After finding the food, it will attract more and more ants. At the same time,
they will take different routes until they find the shortest path.
If ant colony algorithm is applied to edge detection, the initial position of ants should be
placed near the edge of the image detected by the improved Sobel algorithm. According to
the strength of fixed-point pheromone and the probability calculated by heuristic guidance
function, each ant will choose one of eight directions as the next position to move. After
many ite (...truncated)