Abstract
Due to the filter and threshold setting method, the traditional Canny algorithm has the disadvantages of limited denoising ability and poor adaptive ability. Focusing on the filtering part and the threshold setting part, a new image edge detection algorithm based on improved Canny was proposed. In the new algorithm, the Gaussian filtering algorithm is replaced by an improved filtering algorithm, in which the filtering method, weighting method and the size of the filtering window are adaptively selected according to the noise density. In addition, the OTSU algorithm is used to figure out the upper threshold. And an evalution function based on the gradient magnitude histogram and intra-class variance minimization is introduced to help determine the lower threshold The Lena images with differernt pepper and salt noise density were taken as the experiment object. Both the subjective and objective evalution were carried out to verify that the algorithm proposed in this paper has good denoising ability and detail retention ability and that when pepper and salt noise density grows, the new algorithm has more advantages over the adaptive median filtering Canny algorithm and the adaptive weighting median filtering Canny algorithm.
Keywords
Introduction
The edge of the image refers to both the boundary element in the image and the pixel point that highlights the image feature. The large amount of important information contained in the edge of the image makes edge detection an indispensable part of image processing. It has also been widely used and affected many fields [1, 2].
Traditional edge detection algorithms such as Roberts operator and Sobel operator can obtain edges [3], but these operators have limited denoising ability and low precision. Although the traditional Canny algorithm [4] has improved the above problems to a certain extent, its anti-noise ability and adaptability still need to be improved due to the Gaussian variance and the double threshold manual setting problem. In literature [5], the median filtering is used to replace the Gaussian filtering in the traditional Canny algorithm, which makes up for the shortcomings of the traditional Canny algorithm to remove impulse noise. It has achieved good results, but it is limited to the anti-noise ability of ordinary median filtering. The noise immunity is still not outstanding enough. In order to make up for this deficiency, the literature [6] proposes to apply adaptive median filtering combined with wavelet transform to the Canny algorithm to process the image. Although the filtering effect is improved, in the process of expanding the filtering window, it is easy to lose part of the image details; in addition, in the Canny algorithm, whether the upper and lower threshold settings are reasonable directly determines the degree of detail protection of the algorithm. In [7], in the Canny algorithm, morphological smoothing is used instead of Gaussian filtering to preserve the details. The OTSU algorithm is used to adaptively set the upper and lower thresholds to improve the edge continuous effect. However, the threshold setting is too simple and there is still room for improvement. In [8], the OTSU method is improved for the upper and lower threshold setting problems, which ensures that the upper and lower thresholds are adaptively obtained, but the method has better effect on detecting crack images, except that it has limited effect on other types of pictures.
This paper proposes an image edge detection algorithm based on improved Canny. Firstly, the Gaussian filtering part in the traditional Canny algorithm is replaced by the improved adaptive weighted median filtering, and the detail retention effect is further improved by flexible weighting. When the filtering window is adaptively expanded, the corresponding noise density is selected according to the noise density in the window. The image is processed in a weighted manner to reduce the blurring degree of the image while improving the denoising ability. Secondly, the high threshold is obtained by the OTSU algorithm, and an improved evaluation function is introduced to find the lower threshold and improve the edge connection effect.
Canny edge detection algorithm
The traditional Canny operator can be generally divided into four steps when performing edge detection on images [9]: image noise removal, image gradient calculation, image non-maximum value suppression and image edge extraction.
Denoising (filtering) of the image
In this step, the Gaussian filter is selected to process the image. Gaussian filtering is shown in Eq. (1):
In general, the first derivative of a two-dimensional Gaussian function is used to filter the image. The
Let
The gradient vector of the function
The gradient vector can be regarded as a one-dimensional row filter and a one-dimensional column filter, as shown in Eqs (3) and (4):
In the above formula,
Convolving
The above gradients need to be refined to determine edge elements. To do this, it is necessary to find the maximum value of the gray value of the pixel in the local area, and then to replace the gray value of the pixel corresponding to the non-maximum value with 0 to eliminate a large part of the non-edge value, thereby making it more accurate by performing edge positioning. Specifically, in a local area of 3*3, the gray value of the central point pixel is compared with the gray value of other pixel points. If the value of the central pixel point is larger than the adjacent value, the point is the edge point. Otherwise, it means that the point is not an edge point.
Thresholding and edge connection
Let the gradient magnitude matrix obtained in the previous step be
Under normal circumstances, this high and low threshold is set according to the experiment, which leads to the final result is greatly affected by human factors. If the upper and lower thresholds can be reasonably determined, the final edge contour will be more accurate [10].
Improved Canny edge detection algorithm
On the basis of the traditional Canny algorithm, the improved median filtering is introduced to replace the Gaussian filtering part in the traditional algorithm. The improved median filtering has better noise removal and smoothing ability. At the same time, the upper and lower thresholds are improved, attaching the Canny algorithm with a better adaptability.
Improved median filtering
The traditional method is to use Gaussian function for smoothing. However, the parameter
In this paper, the improvement of the filtering algorithm has these points: 1) Set the noise point judgment mechanism to ensure that only the noise point accepts the filtering; 2) Adapively expand the filtering window to improve the filtering effect; 3) Combine the proportion of the noise points in the window, adopt flexible adaptation The weighting method weights the elements in the filtering window under different conditions, and improves the median accuracy of the output, and also improves the loss of picture detail caused by window expansion.
Noise point detection
The perfection of the noise judgment mechanism can improve the accuracy of noise detection [12]. Such methods emerge in an endless stream. This paper refers to the detection method given in [13, 14]. When the image noise is determined, the window is not fixed. As the window is continuously expanded, the noise point detection in the window is performed. Taking a 3*3 window as an example, the gray value of the center pixel
The average value of the pixels in the window is as shown in Eq. (10):
Let
However, if there is a special case where the gray values of all the points in the window are the same, it is determined that there is no noise point in the window. In addition, if the proportion of salt and pepper noise in the image to be processed is large, it may be considered to partially modify the determination condition, that is,
In this paper, the noise point is re-evaluated for each element in the window when the window is enlarged for each noise point. This is not only related to the window adaptation but also to the weighting method.
The window size affects the denoising performance of the traditional median filtering algorithm. Under the premise that the center point of the window is a noise point, the adaptive window size change method mainly depends on the number of noises in the window. The noise number in the window is num1, and the non-noise number is num0. The window size starts to increase gradually from 3*3 (filter radius
The number of noises in the window is 1, that is, when num The number of noises in the window is equal to the total number of elements in the window, that is, when num After the center point in the window is replaced, it is still mistakenly judged as noise, and the window continues to expand. This is the most basic requirement of the adaptive filtering algorithm. If the center value is still a noise value after replacement, the filtering algorithm will be invalid.
When the size of the adaptive template is too large, this means that the picture details are very serious. In order to improve the performance of protecting the details of the picture, the adaptive window variation range of this paper is limited to 3*3, 5*5, 7*7 accordingly.
One disadvantage of the adaptive filtering algorithm is that when the filtering window becomes larger, the local area gray value variation may be large, resulting in loss of detail. This paper considers that different elements in the window are given different weights in the process of window enlargement to improve the loss of detail. For the difference in noise density, this paper sets two weighting methods.
When the number of noise points in the filtering window is smaller than the number of non-noise points, the noise density in the filtering window is considered to be small, and the similarity is used to weight; for a certain noise point
Where The closeness of the pixels in the window is calculated one by one, and then sorted by increasing in size, and the Obtaining the median value by such a method can not only satisfy the requirement of expanding the window lifting filtering effect, but also can improve the detail protection effect to some extent. When the number of noise points in the filtering window is larger than the number of non-noise points, the noise density in the filtering window is considered to be large at this time, and the weighting method using only the gray value of the non-noise point is adopted.
In the actual filtering process, when the noise density in the filtering window is large, the median value obtained by the first weighting method does not belong to the noise point in the noise judging mechanism, and the probability of changing the details of the original image is still large, so in this case, it is considered to use a weighting method that only refers to the gray value of the non-noise point in the filter frame.
Taking the case of the
Where
This weight is used to measure whether the non-noise point in the frame is close to the center point. Obtaining the median value by such a method can avoid the too much change in the detail of the mean filtering, also making the value of the output close to the middle value of the non-noise point.
Scanning all pixel gray values of the image in a frame order of 3*3 (in this case, Counting the number of noise points in each frame num If num To determine the obtained Repeat the above steps until the pixels of the full image are processed.
The flow chart of the algorithm is shown in Fig. 1.
Improved median filtering algorithm flow chart.
First, the paper uses the OTSU algorithm [15] to automatically select the upper threshold. The basic idea of the OTSU algorithm is to use the threshold to divide the image pixels into two categories, obtaining their maximum variance between classes as well as the most suitable threshold.
Supposing that the total number of pixels of a graph
The total grayscale mean of the entire image is calculated by Eq. (17):
The variance between classes is defined as Eq. (18):
In [15], an evaluation function based on gradient magnitude histogram and intra-class variance minimization is proposed. It is reasonable to set the upper and lower thresholds
The image pixels after maximum suppression are divided into non-edge point pixels, edge point pixels, and suspected edge point pixels, where
Considering that
Then the maximum value of
In order to prove the effectiveness of the improved algorithm in this paper, under the experimental conditions of hardware and software conditions of Win7-64, Intel(R) Core(TM) i7-6700HQ CPU @2.60 GHz, Matlab2014a, select Lena with size 512*512. The image is used as an experimental object. In the case of adding noise (0.2 salt and pepper noise) and no noise, the improved median filtering algorithm and Median Filtering Algorithm (MF) and adaptive median filtering algorithm (Adaptive Median Filtering Algorighm) , AMF), Adaptive Weighted Median Filtering Algorithm (AWMF) comparison experiment, also improved Canny algorithm and traditional Canny algorithm (TC), AMFCanny algorithm (AMFC), AWMFCanny algorithm (AWMFC) ) Edge detection effect comparison experiment.
Comparison of filtering algorithms
Subjective evaluation of filtering algorithms
Comparison of filtering effects.
In Fig. 2, Fig. 2a–h are the original Lena diagram, the Lena diagram with 20% salt and pepper noise, the MF processing result with template size of 3*3, and the MF processing result with template size of 5*5. Figure, AMF processing result map with adaptive template upper limit limited to 7*7 (maximum filter radius Rmax
It can be seen from Fig. 2c and d that when the noise density is large, the 3*3 template MF has almost failed, and the 5*5 MF can effectively remove the noise point, but the picture is blurred, that is, lost a lot of details of the original picture. It can be seen from Fig. 2e and f that when the filtering radius of AMF is limited to be small (Rmax
In this paper, the Peak Signal-to-Noise Ratio (PSNR), the residual noise RMSErn and the collateral distorion RMSEcd are used to evaluate the merits and demerits of the algorithm. The calculation method is as shown in Eqs (21) and (22).
Where:
For the original image containing the gray level
Among them, hrn refers to the deed of the residual noise caused by insufficient processing, and hcd is related to the distortion problem caused by excessive smoothing.
Where
If the PSNR value is large, it means that there are fewer noise points in the filtered picture. RMSErn can be used to evaluate the denoising ability of the algorithm. RMSEcd is used to measure the degree of image distortion obtained after processing. The smaller the two values are, the filtering effect is better.
In this paper, each algorithm is run independently for 30 times and then averaged. After adding 10%
Comparison of objective evaluation indicators for denoising
It can be seen from Table 1 that the PSNR, RMSEcd, and RMSErn indicators of this method are better than AMF and MF, and the filtering effect, detail retention, and image restoration are greatly improved. Compared with AWMF, the algorithm fails to surpass RMSEcd and RMSErn. However, the larger the noise density is added, the better the PSNR performance and stability of the proposed method is.
Subjective evaluation of edge extraction effect
Compared with TC, AMFC, AWMFC algorithm and the improved filtering Canny edge extraction effect when no noise is added. In Fig. 3, the threshold values of Fig. 3a and b are the optimal thresholds determined by multiple trials. Comparing Fig. 3a with d, it is easy to see that the left side door frame part of the original image is more clear in the image. The upper right corner of the cap is used to restore the fold to the image. The original features were restored to the extent. Comparing Fig. 3b with Fig. 3d, Fig. 3d is more smooth on the connection of the line, which shows the advantage of threshold selection, reflected in the door frame on the left side of the image. Comparing Fig. 3c with Fig. 3d, the former has more edge burrs, and the detail reduction effect is slightly worse than the latter.
Noise-free Canny effect comparison.
Canny effect comparison under nosied circumstance.
Experiments show that less than 5% of salt and pepper noise has largely affected the edge detection effect of the traditional Canny algorithm. This is mainly because this part of the noise can not be effectively eliminated. Therefore, in the case of adding noise, only the effects of the AMFC algorithm, the AWMFC algorithm and the improved filtered Canny algorithm are compared, wherein the threshold of the AMFC algorithm is an empirical value.
Comparison of objective evaluation indicators for edge detection
Figure 4 shows the effect of each method after adding different salt and pepper noises, wherein Nmax of the AMF in Fig. 4a is 10, and Nmax of the adaptive median in Fig. 4d is 3. It can be seen from the four graphs of Fig. 4a, b, d, and e that the edge detection effect of AMFC and AWMFC is more or less affected after noise is added. Comparing Fig. 4a with Fig. 4c, it can be found that at 0.1 noise density, although the result of AMFC is close to the result of improved Canny filter in this paper, because the filter radius is too large, many details are lost, such as the door frame. The missing edge details, some of the brim connections are intermittent, and false edges appear. The experiment found that when the maximum filter radius of the AMFC algorithm is limited to 3, the effect of the noise point on the detection effect is already obvious. This is in the comparison of Fig. 4d–f. It can be seen very intuitively. As can be seen from the comparison of Fig. 4d and e, compared with the AMFC algorithm, the AWMFC algorithm performs better under noise conditions, mainly due to its filtering effect. In this paper, the filtering effect is better, and the final edge effect should be better, which is verified in Fig. 4f.
In order to better quantitatively evaluate the edge detection algorithm, MSE (Mean Square Error), PSNR (peak signal to noise ratio), and information entropy (IE) are used as indicators for objective evaluation.
Information Entropy (IE): The entropy value reflects the amount of information contained in the image. In this paper, because the image containing noise is processed, the denoising effect is poor, and the resulting edge image contains more points, including More noise points. Therefore, the larger the information entropy is, the worse the edge extraction effect is. The indicator can be defined as:
In the formula, MSE (mean square error): The definition has been given in the foregoing. It should be noted here that the smaller the mean square error is, the closer the edge image after processing is to the original structure; PSNR (peak signal to noise ratio): used to measure the overall quality of the obtained edge image. The larger the PSNR value, the more accurate and complete the edge extraction.
In this paper, the modified Canny algorithm and the AMFC and AWMFC algorithms are used to experiment with the Lena diagram with 10% and 20% , 30% noise, and the edges are obtained, and the above three indicators are used for objective evaluation, as shown in Table 2.
As can be seen from the table above, since the filtering part of Canny is improved in this paper, the noise points in the image can be effectively filtered out during processing, so the value of IE is smaller than the IE values of the other two Canny algorithms. Overall, the MSE size of the algorithm is smaller than the MSE value of the comparison algorithm, reflecting that the algorithm has higher accuracy for image edge acquisition. From the perspective of PSNR value, the performance of this algorithm is more prominent, which can ensure the overall quality of the edge image to a greater extent as well as extract the edge details of the original image better.
In this paper, the traditional Canny algorithm is used to study the three shortcomings of poor anti-noise ability, threshold value manual setting and poor adaptive ability. Experiments show that the improved filtering algorithm is better than MF algorithm, AMF algorithm and AWMF algorithm. And as the noise density grows, both the denoising ability and the detail protection ability make a better performence. When it is noise free, the Canny algorithm proposed in this paper can obtain more details than the TC, AMFC and AWMFC algorithms. When noise is added, the AMFC algorithm and the AWMFC algorithm retain more detail while reducing the generation of false edges, showing its better noise removing ability.
Footnotes
Acknowledgments
National Natural Science Foundation of China (No. 61663009); JKey Project of Jiangxi Science and Technology Support Program (No. 20161BBE50081).
