# Texture Construction Edge Detection Algorithm
## 2 Texture Construction Edge Detection Algorithm
### Image Preprocessing  
Since the grayscale image retains most of the edge information in the image, the color image containing the three color components R (red), G (green), and B (blue) is first converted into the grayscale image. The grayscale image is gray-scaled by the commonly used grayscale formula, which is expressed as follows:  
\[\mathrm{Gray}=0.299\times\mathrm{R}+0.587\times\mathrm{G}+0.114\times\mathrm{B} \tag{1}\]  
Image capture will be affected by imaging application-related technologies, such as the generation of scattered noise due to a dark current during the operation of the optical device, error propagation caused by the chromaticity coordinate reading and the color space conversion process, shooting angle, and external environmental factors such as the rough surface of the object affected by light and shadow, so the generation of noise is inevitable in the process of image acquisition. Therefore, to reduce the noise caused by the above reasons, the image edge is obviously disturbed. First, the grayscale image, \(f\) (\(x\), \(y\)), is smoothed using a two-dimensional Gaussian function filter. The Gaussian function aims to calculate the transformation of each pixel in the image by using a normal distribution. The two-dimensional normal distribution equation \(h\) (\(x\), \(y\)) is defined as follows:  
\[h(x,y)=\frac{1}{2\pi\sigma^{2}}e^{-\frac{x^{2}+y^{2}}{2\sigma^{2}}} \tag{2}\]  
where \(\sigma\) (preset value is 1) is the standard deviation of the normal distribution. After image smoothing is completed, the filter mask of [PERSON] (2018) is used to find the gradient value of each pixel in the image, using a 3 \(\times\) 3 horizontal mask \(h_{x}\), as Equation (3), and the vertical mask \(h_{y}\), as Equation (4). After obtaining the gradient values in the horizontal and vertical directions (i.e., \(G_{x}\) and \(G_{y}\)), the gradient amplitude and angle of each pixel are obtained by Equations (5) and (6) to obtain the results of the gradient value (\(\text{grad}\,f\)) and the gradient angle (\(\theta\)), respectively. The relevant operation formula is expressed as follows:  
\[h_{x}=\left[ \begin{array}{ccc}-1&-2&-1\\ 0&0&0\\ 1&2&1\end{array} \right] \tag{3}\]  
\[h_{y}=\left[ \begin{array}{ccc}-1&0&1\\ -2&0&2\\ -1&0&1\end{array} \right] \tag{4}\]  
\[\text{grad}\,f=\text{mag}(\
abla\text{G})=\left[G_{x}^{2}+G_{y}^{2}\right]^{ \frac{1}{2}} \tag{5}\]  
\[\theta=\tan^{-1}\left(\frac{G_{y}}{G_{x}}\right) \tag{6}\]  
Through the gradient amplitude obtained by the above operation, the change between the adjacent pixels in the image can be observed. This algorithm is included as an effective block texture feature when the pixel gradient amplitude is not zero. Therefore, when the pixel displays any gradient amplitude change in the process, it will be included in the subsequent algorithms to be dealt with. Therefore, to avoid excessive interference of the edge texture in the image to establish an effective block edge texture feature, the pixel with a smaller gradient amplitude is regarded as noise in the algorithm and a fixed threshold value is set to filter. In addition, the analysis is retained for further analysis by retaining valid texture features. After several image experiments, the gradient threshold parameter is set to 15. Figure 1 shows the process through which the algorithm uses a fixed threshold to filter out noise. Figure 1a shows the original image, and there are many inconspicuous faint light and shadow changes in the roof, door panel, and wall surface. Figure 1b shows the binarized image from Figure 1a, with a gradient amplitude greater than zero after image pre-processing, which produces considerable noise texture due to noise generation and light and shadow changes.