Keywords

1 Introduction

The edge of an image is one of the basic features, and a clear and accurate edge extraction result is helpful to improve the accuracy of feature extraction and pattern recognition [1]. However, in the real environment, noise often affects the result of image edge detection, making the boundary inconspicuous, so many scholars in this field have conducted corresponding research before.

In the field of image processing, noise and edges often belong to the same high frequency signal, so in order to eliminate noise interference, it is first necessary to filter out the noise signal at the gray gradient level while maintaining the edge information of the target. However, if the filtering is not correct, the edges of the image may also be filtered out at the same time, resulting in the discontinuous edge of the extracted image [2]. Secondly, due to the illumination and the object itself, the edges often exist on different scales. And caused by different grayscale differences, the difference range between the gray level of the edge pixel and the background gray level is often unknown, so the edge of the image also has the characteristics of the edge grayscale gradient difference. Therefore, it is often difficult to detect the complete image edge by the traditional method based on the grayscale difference operator alone [3].

In recent years, with the development of deep convolutional neural networks, methods to detect image edges using neural networks have been proposed continuously. Dense extreme inception network for edge detection (DexiNed) [4], richer convolutional features (RCF) [5], learning to predict crisp boundaries (LPCB) [6] and other models have already achieved good results and these networks provide a new idea for image edge detection. However, due to the imbalance between the height of the background area and the object boundary in the image and the characteristics of the convolutional neural network, the extracted image edges are relatively thick, and the ability to extract the edges of small objects is weak [7]. Traditional multi-directional morphological edge detectors can effectively extract the edges in the image, but for different use scenarios, it takes a lot of time and energy to select the synthesis coefficient, which seriously affects the effect of multi-directional morphological edge detection and the efficiency of the detector [8].

Therefore, aiming at the above problems, according to the characteristics of image noise signal and illumination transformation, a multi-directional morphological edge detection algorithm based on fuzzy logic judgment strategy is proposed in this paper. First, the noisy image is morphologically filtered by the morphological binary structure group, then a set of improved multi-directional morphological operators are used for gray-level edge detection, next the image after morphological edge detection is combined with fuzzy logic inference strategy for boundary enhancement and non-boundary points and interference noise weakening, and finally the region containing edges is segmented by the two-dimensional K-means method to obtain the final image of the target edge profile.

2 Multi-directional Edge Detection Algorithm Based on Fuzzy Logic Inference

2.1 Multi-directional Adaptive Weight Edge Detection

2.1.1 Small-Scale Morphological Filtering

In the operation of morphological filtering, this paper first uses two structural elements A and B to construct mathematical relations such as morphological open and closed operations for noise reduction of the original image respectively, so as to reduce the effect of noise on the edge detection effect. This morphological filtering operation can effectively remove the noise while better preserving the edge information of the image.

$$A = \left[ {\begin{array}{*{20}l} 1 \hfill & 0 \hfill & 1 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ 1 \hfill & 0 \hfill & 1 \hfill \\ \end{array} } \right],B = \left[ {\begin{array}{*{20}l} 0 \hfill & 1 \hfill & 0 \hfill \\ 1 \hfill & 1 \hfill & 1 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ \end{array} } \right]$$
(1)

Morphological operations use pre-defined structural elements to match images to extract signals and suppress noise. Since in grayscale images, the morphological open operation suppresses the peak (positive pulse) noise in the signal, while the morphological closed operation suppresses the bottom valley (negative pulse) noise in the signal. Therefore, in the re-Eq. (1) of this paper, the signal is averaged after two opposite operations of open operation and closed operation, which is equivalent to smoothing the signal twice, which has the effect of removing the orphan point of image noise. The morphological filtering operation is defined as

$$F_0 = \frac{1}{2}(f \circ A \cdot B + f \cdot A \circ B)$$
(2)

f is the original image and F0 is the denoised image after morphological filtering. “\(\circ\)” is on behalf of the open operation and “\(\cdot\)” is on behalf of the close operation. The filtering effect is shown in Fig. 1.

Fig. 1.
figure 1

Image noise filtering effect comparison (a) Original image with salt and pepper noise (b) processed image

2.1.2 Multi-directional Edge Extraction

In the method based on gray gradient detection, in order to effectively detect the edges in different directions in the image and avoid the phenomenon of missed detection, this paper adopts the method of detecting and extracting the edge information of the image in different directions. Four 3 × 3 linear structural elements C1, C2, C3, C4 with directions of 0°, 45°, 90°, 135° are constructed respectively. The structural elements are shown as (3).

$$\begin{gathered} {{{\rm C}}}_1 = \left[ {\begin{array}{*{20}l} 0 \hfill & 0 \hfill & 0 \hfill \\ 1 \hfill & 1 \hfill & 1 \hfill \\ 0 \hfill & 0 \hfill & 0 \hfill \\ \end{array} } \right],{{{\rm C}}}_2 = \left[ {\begin{array}{*{20}l} 0 \hfill & 0 \hfill & 1 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ 1 \hfill & 0 \hfill & 0 \hfill \\ \end{array} } \right] \hfill \\ {{{\rm C}}}_3 = \left[ {\begin{array}{*{20}l} 0 \hfill & 1 \hfill & 0 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ \end{array} } \right],{{{\rm C}}}_4 = \left[ {\begin{array}{*{20}l} 1 \hfill & 0 \hfill & 0 \hfill \\ 0 \hfill & 1 \hfill & 0 \hfill \\ 0 \hfill & 0 \hfill & 1 \hfill \\ \end{array} } \right] \hfill \\ \end{gathered}$$
(3)

Through performing the edge detection on the image F0 after morphological filtering by using structural elements in 4 directions, and using morphology to perform operations such as corrosion, expansion, opening and closing operations on the image, the edge detection results of the image in four different directions can be obtained respectively.

Firstly, by performing two morphological operations on the grayscale image after noise reduction, this paper obtains the grayscale image ydi that preserves the dark detail edges of the original grayscale image and the grayscale image yei that preserves the bright detail edge of the original grayscale image, as shown in Eqs. (4) and (5). In order to obtain the edge details, the maximum values Emax, i and minimum values Emin, i after edge extraction of each pixel are calculated separately, as shown in Eqs. (7) and (8), and the difference between the two is supplemented by the result of edge extraction as the detail information of the edge, as shown in Eq. (6).

$$y_{d_i } = F_0 \oplus C_i \circ C_i - F_0 \cdot C_i$$
(4)
$$y_{e_{\text{i}} } = F_0 \cdot C_i - F_0 \Theta C_i \cdot C_i$$
(5)
$$y_{de_i } = y_{d_i } + y_{e_i } + \lambda \left( {E_{\max ,i} - E_{\min ,i} } \right)$$
(6)
$$E_{\max ,i} = \max \left\{ {y_{d_i } ,y_{e_i } } \right\}$$
(7)
$$E_{\min ,i} = \min \left\{ {y_{d_i } ,y_{e_i } } \right\}$$
(8)

In the formula, the edge information ydi and yei are obtained by constructing two mathematical relations between morphological operations. In order to enhance the details of the edge, calculate the maximum Emax, i and minimum Emin,i of each pixel after edge extraction. The difference between the two parameters is used as a supplement to the details of the edge of the image, and ydei is the detection result obtained after the processing of the structural element Ci. In the formula, the parameter λ = 1.

The four kinds of structural elements are used to detect the edges of the image respectively, and the edge detection sub-images in four directions can be obtained, thereby completing the multi-directional extraction of the image edges. The multi-directional extraction is shown in Fig. 2.

Fig. 2.
figure 2

Multi-directional edge detection sub-image

2.2 Fuzzy Logic Reasoning Strategy

2.2.1 Noise Reduction Image Gradientization

Since the multi-directional edge detection operator detects edges only from a morphological point of view by comparing neighboring pixel intensities, a small intensity difference between two neighboring pixels does not always indicate an edge because uniform regions are often not explicitly defined. Therefore, the multi-directional morphology detection operator sometimes detects some non-boundary pixels, which affects the subsequent image processing process.

To solve the above problems, this paper refers to the inference strategy of fuzzy logic to assist the decision making by establishing the edge affiliation function of pixels in the image, so as to achieve the purpose of boundary enhancement as well as non-boundary pixel suppression for the results after multi-directional edge extraction.

The process of fuzzy logic inference strategy is shown as follows. First, in this paper, the original denoised image is regarded as a two-dimensional discrete function, and a pair of gradient filters Gx and Gy are set to derive this two-dimensional discrete function, which are shown as follows.

$$G_x = \left[ { - 1,1} \right],G_y = \left[ \begin{gathered} { + }1 \hfill \\ - 1 \hfill \\ \end{gathered} \right]$$
(9)

The derivative of the two-dimensional discrete function of the image is shown in Eq. (10).

$$\left\{ \begin{gathered} G(x,y) = dx(i,j) + dy(i,j) \hfill \\ dx(i,j) = I(i + 1,j) - I(i,j) \hfill \\ dy(i,j) = I(i,j + 1) - I(i,j) \hfill \\ \end{gathered} \right.$$
(10)

For the original noise-reduced image, this paper uses the above gradient filters Gx and Gy to convolute the image I respectively, so that the gradient matrices Ix and Iy along the horizontal and vertical directions of the image can be obtained, and the value domain interval is [−1,1]. The flow is shown in the following Fig. 3.

Fig. 3.
figure 3

Noise reduction image horizontal and vertical gradientization

2.2.2 Input Gradient Image Variable Fuzzification

IX and Iy of two gradient image pixel points are used as inputs to the fuzzy inference system edgefis. For each input, this article uses a 0-mean Gaussian affiliation function to map the gradient value of that point to between 0 and 1, meaning the degree to which the gradient belongs to ZERO. If the pixel has a gradient value of 0, then the degree of affiliation that it belongs to ZERO is 1. The Gaussian affiliation function is shown in Eq. (11).

$$\left\{ \begin{gathered} f(x;\sigma ,c) = e^{\frac{ - (x - c)^2 }{{2\sigma^2 }}} \hfill \\ f(y;\sigma ,c) = e^{\frac{ - (y - c)^2 }{{2\sigma^2 }}} \hfill \\ \end{gathered} \right.$$
(11)

The degree to which a pixel point belongs to zero (non-edge pixel point) is defined using the 0 mean Gaussian affiliation function, where σ is the standard deviation and is set to 0.1 and c is the mean value of 0.

Since the two-dimensional matrix calculated by the Gaussian membership function is the likelihood estimation of non-edge pixels, it is further calculated to obtain the edge gradient likelihood estimation of the input image pixels, denoted as Gx and Gy, respectively, as shown in Eq. (12) Show. The input image blur flow chart is shown in Fig. 4.

$$\left\{ \begin{gathered} G_x = 1 - f(x;\sigma ,c) \hfill \\ G_y = 1 - f(y;\sigma ,c) \hfill \\ \end{gathered} \right.$$
(12)
Fig. 4.
figure 4

Flow diagram of input image Ix and Iy blurring

2.3 Fuzzy Logic Enhancement Strategy

In order to enhance the edge strength of the multi-directional gradient map while suppressing the pixel interference of non-edge points, this paper adopts a fuzzy logic [9] inference strategy to assist in the decision making of the edge images, and for the edge detection images in four directions, four different weighting strategies are used to process the multi-directional edge extraction results.

For the edge detection results in the C1 and C3 directions, this paper uses the Px and Py likelihood probability matrices to weight them to obtain the edge likelihood probabilities P1 and P3, while the joint likelihood probability matrix of Px and Py is used to compare C2 and C4 The input image of the direction is weighted to obtain P2 and P4. The specific formula is shown in (13).

$$\left\{ \begin{gathered} P_1 { = }P_y \hfill \\ P_3 = P_x \hfill \\ P_2 = P_4 = \left( {P_x + P_y } \right)/2 \hfill \\ \end{gathered} \right.$$
(13)

After obtaining the likelihood probabilities of the edges in the four directions, this paper calculates the likelihood probabilities through a third-order function to obtain the gain results of the corresponding pixels on the images in each direction. The third-order gain function is shown in Eqs. (14) and (15).

$$T_i = \left[ {k \times (x - th)} \right]^3 + 1$$
(14)
$$G_i = \left\{ \begin{gathered} T_i T_i > 0 \hfill \\ 0 T_i < 0 \hfill \\ \end{gathered} \right.$$
(15)

In Eq. (13), Ti represents the gain of each pixel of the image corresponding to the direction i, and k represents the gain adjustment coefficient, which can adjust the strength of the edge and non-edge pixel gain or attenuation, and the value of k is 2.5 in this paper. th represents the critical threshold for judging edges and non-edge pixels. In this paper, the value of th is 0.6. The likelihood probability higher than th will be judged as an edge point, and the pixel value of the corresponding point will be increased by gain. And in Eq. (14). Otherwise, it will be judged as a non-edge point. The value of the corresponding pixel will be attenuated, so as to achieve the purpose of widening the grayscale difference between edge pixels and non-edge pixels. The process of multi-directional edge extraction image enhanced by fuzzy logic is shown in Fig. 5.

Fig. 5.
figure 5

Multi-directional edge extraction image is enhanced by fuzzy logic

2.4 Direction Adaptive Weight Fusion

After the image is processed by the multi-directional morphological detection algorithm, four directional edge detection results are obtained. When the morphological algorithm is used to extract the edge of the image, the edge of the image can be determined by the difference of the grayscale values obtained after the processing of structural elements [10]. The larger the value is, the greater the probability that there is an image edge in the vertical direction of the structural element is.

Therefore, by calculating the sum of the grayscale value changes of the structural elements of each pixel in different directions in the image, the proportion of edges in different directions can be obtained, and this can be used as the direction weight of the image [11]. As shown in the 3 × 3 image area in Fig. 6, the center pixel of this area is p5, and di is defined as di = |pi-p5|, where di represents the grayscale difference between pixel i and the center point of the image area. The sum of the gray change values of a central pixel in the four directions defined by Ci are Dc1, Dc2, Dc3, Dc4, respectively. The specific definition is shown in (16).

$$\begin{gathered} D_{c_1 } = d_1 + d_2 + d_3 + d_7 + d_8 + d_9 \hfill \\ D_{c_2 } = d_1 + d_2 + d_4 + d_6 + d_8 + d_9 \hfill \\ D_{c_3 } = d_1 + d_4 + d_7 + d_3 + d_6 + d_9 \hfill \\ D_{c_4 } = d_2 + d_3 + d_6 + d_4 + d_7 + d_8 \hfill \\ \end{gathered}$$
(16)
Fig. 6.
figure 6

An example of a set of 3 × 3 feature regions in an image

In order to obtain the proportion weight of the edges in different directions in the whole image, define \(D^{\prime}_{c_1 }\) as the sum of the gray value changes in all directions after traversing all the pixels in the image, then the direction adaptive weight wi of sub-image fusion is defined in (17).

$$w_i = \frac{{D_{c_i }^{\prime} }}{{\sum_{j = 1}^4 {D_{c_j }^{\prime} } }},i = 1,2,3,4$$
(17)

After completing the calculation of multi-directional edge extraction and direction adaptive weight, the multi-directional edge detection result and the direction adaptive weight are weighted and summed to obtain the final edge detection result as shown in (18).

$$Y = \sum_{i = 1}^4 {w_i } y_{de_i }$$
(18)

Through the fusion of sub-images in various directions, the fusion result Y of the proposed adaptive multi-direction anti-noise morphological edge detection algorithm is obtained. The fusion process of multi-direction sub-images is shown in Fig. 7.

Fig. 7.
figure 7

An example of a set of 3 × 3 feature regions in an image

2.5 Two-Dimensional K-means Adaptive Threshold Segmentation

Next, in order to eliminate the existence of continuous low-frequency noise, the two-dimensional K-means [14] method is adopted to segment the image. The K-means algorithm is an unsupervised classification algorithm based on the proximity rule in pattern recognition, but the classification algorithm based on one-dimensional histogram only considers the gray value information of the image. More sensitive to isolated points, the two-dimensional K-means algorithm increases the influence of pixels and low-frequency noise on the class center value. Let f(p) be the grayscale of pixel p(x, y), and the average grayscale value of the defined area is shown in (19).

$$h(p) = \frac{1}{S(\sigma )}\sum_{p_i \in \sigma } f \left( {p_i } \right)$$
(19)

In the formula, σ is the area centered on the pixel of p(x, y), and S(σ) is the area of the area. Image IM×N(x, y) can generate M × N data pairs (f(p), h(p)). The subsequent processing is similar to the one-dimensional K-means clustering algorithm process, that is, the initial cluster center is selected; the above process is repeated until the position of the cluster center no longer changes. The result of adaptive threshold segmentation is shown in Fig. 8.

Fig. 8.
figure 8

Adaptive threshold segmentation results based on two-dimensional k-means algorithm

3 Simulation and Analysis

In the field of image processing, the evaluation criteria for evaluating image quality are divided into subjective evaluation and objective evaluation to judge the quality of images. Its advantage is that it can truly reflect the visual quality of the image [15], while the objective evaluation index is mainly based on a series of quantitative data to evaluate the image and analyze the data through a formula to derive a judgment on the image quality.In order to intuitively express the edge extraction results of the algorithm used in this paper on low-quality images with noise [16], this paper adds salt and pepper noise and Gaussian noise to the input image to reduce the image quality, and uses classic edge detection algorithms related to this field. The proposed algorithm is processed to achieve the purpose of testing the edge detection results of various algorithms, so as to obtain the subjective visual comparison results of image processing.

In the first set of experiments, the pepper noise is added to the original image, and various edge detection algorithms are adopted to perform image edge extraction detection and compare the extraction results. The image edge extraction results of different algorithms are shown in Fig. 9. And in the second set of experiments, the Gaussian noise is added into the original image, the results of edge detection are shown in Fig. 10.

Fig. 9.
figure 9

Comparison of detection results of various algorithms for images with salt and pepper noise

Fig. 10.
figure 10

Comparison of detection results of various algorithms for images with Gaussian noise

Through the results of processing low-quality images with added salt and pepper noise and Gaussian noise through the various algorithms in the above figure, it can be found that traditional classic algorithms such as Canny [7], Prewitt [8], Robert [9] and Sobel [10] will suffer from greater noise when processing low-quality noisy images, which is not conducive to the further processing of subsequent images. The edge detection algorithms such as PhaseCong and Fuzzy have better noise suppression effects, but the detailed information of the image will be lost a lot, and it will also cause the edge of the image to appear discontinuous after detection, Therefore, it will also affect the subsequent image processing. As can be seen from the above figure, the algorithm proposed in this paper has a strong suppression effect on both pepper noise and Gaussian noise, and also has an excellent edge retention effect on both foreground and background, which retains more details. Therefore, the algorithm we proposed has an excellent performance.

4 Conclusion

Based on previous studies, we proposed a multi-angle morphological edge detection algorithm combined with fuzzy logic inference strategy for the problem of edge detection of noisy images, which can achieve edge enhancement as well as noise and non-edge suppression by generating an image two-dimensional fuzzy matrix to assist in judging the images after multi-directional edge detection. As a result, the proposed method can not only effectively reduce the noise interference in the image, but also make the detected edges more clear and continuous, which can achieve better image edge detection results.