# An Image Edge Detection Algorithm Based on an Artificial Plant Community
## 4 Algorithm Design  
### Image Preprocessing  
Referring to the principles of the Sobel algorithm [47] and Canny algorithm [48], four main steps are used to preprocess the image in order to provide a living environment for the APC algorithm. \begin{table}
\begin{tabular}{c c} \hline \hline
**Symbol** & **Definition** \\ \hline \(l\) & An image \\ \(w\) & Image width \\ \(h\) & Image height \\ \(L\) & Grey level \\ \(Th_{H}\) & High threshold \\ \(Th_{L}\) & Low threshold \\ \(i\) & Pixel number \\ \(S\) & Population size \\ \(K\) & Maximum number of iterations \\ \(k\) & Iteration counter \\ \(x\) & Artificial plant individual \\ \(p_{s}\) & Seeding probability \\ \(p_{g}\) & Growing probability \\ \(p_{f}\) & Fruiting probability \\ \(Obj\_fun()\) & Value of the evaluation function \\ \(e\) & Error of the evaluation function \\ \(e_{th}\) & Error threshold \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Symbol Definitions. First, the original image needs to be formatted, where the original color image is converted into a grayscale image. An original image \(I_{\text{original}}(i,j)\) will be converted into a grayscale image \(I_{\text{gray}}(i,j)\) with a gray level of \(L\). Second, the noise contained in the grayscale image \(I_{\text{gray}}(i,j)\) is filtered out and the level of disturbance in image edge detection is decreased. Because most of the noise in the image is Gaussian noise, the Gaussian filter can help us to obtain images with a higher signal-to-noise ratio (SNR) [7,33]. The Gaussian filter is a linear smoothing filter that is suitable for eliminating Gaussian noise and is widely used in the noise reduction process of image processing. According to the Sobel operator [47] and Canny operator [48], the Gaussian filter is used to find the weighted average pixel values of the whole image, where the value of each pixel is obtained by a weighted average of its own value and the neighbor pixels values. A Gaussian function can be written in a separable form, so a separable filter can be used for acceleration; that is, a multidimensional convolution can be converted into multiple one-dimensional convolutions. The two-dimensional Gaussian filtering of a gray image \(I_{\text{gray}}(i,j)\) involves one-dimensional convolution on the row first, and then one-dimensional convolution on the column, which greatly reduces the computational complexity [7,33]. The two-dimensional Gaussian distribution function \(G(i,j)\) is used to calculate the convolution values of the grayscale image in the horizontal and vertical directions \(I_{\text{gray}}(i,j)\). \[G(i,j)=\frac{1}{2\pi\sigma^{2}}\exp(-\frac{i^{2}+j^{2}}{2\sigma^{2}}) \tag{1}\]  
where \(\sigma\) is the standard deviation of the Gaussian smoothing filter \(G(i,j)\), which controls the smoothing degree of the grayscale image \(I_{\text{gray}}\). If the value of \(\sigma\) is small, it will be a precise edge but with more noise, but if the value of \(\sigma\) is big, it will be an imprecise edge but with less noise. After applying the Gaussian smoothing filter, the image \(I_{\text{gray}}(i,j)\) will change as follows:  
\[I(i,j)=G(i,j)*I_{\text{gray}}(i,j) \tag{2}\]  
where \(*\) is the convolution operation. Now the filtered image \(I(i,j)\) can be obtained, ready to be processed for edge detection. Third, after the convolution operation and filtering, the habitable gradient, amplitude, and direction are obtained. The traditional operator calculates the first-order partial derivative finite difference of the pixels in the \(2\times 2\) convolution template to approximately obtain the habitable gradient amplitude and direction of the image \(I(i,j)\).