## 3 Methods
### Data Collection and Pre-Processing
#### 3.2.3 Image Processing Data Pre-Processing  
Grayscale  
The color of a color image is jointly determined by the three components of R, G, and B, but RGB does not reveal the morphological characteristics of the image; instead, the color is adjusted according to the optical principle. Therefore, converting a color image into a grayscale image that contains only luminance information but not color information helps reduce computational effort. Grayscale can transform a color image into a grayscale image by deleting all the color information of the image and only retaining the brightness of each pixel. Grayscale processing methods primarily include the component method, maximum method, average method, weighted average method and so on. The weighted average method effectively enhances data features, thereby enabling the model to better learn crack information. Therefore, in this paper, we employ the weighted average method for grayscale preprocessing of images. The three-channel components of the color image are weighted and averaged according to the importance of each channel, and then the resulting weighted average is used as the gray value of the grayscale image. The gray value is shown in Equation (1).  
\[\rm{f(x,y)=0.299R(x,y)+0.587G(x,y)+0.114B(x,y)} \tag{1}\]  
Image Enhancement  
In the infrastructures, the difference between the crack and the surrounding background color is generally small, which can lead to a lack of crack contrast. In order to make the edges of the cracks more prominent, the image's contrast needs to be enhanced. The grayscale range measures contrast. The larger the range, the higher the contrast and the clearer the image. Contrast enhancement is based on the grayscale histogram. The grayscale histogram is a function of the grayscale level of the image, which is used to  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Data Sets** & **Percentage** & **Set Size** \\ \hline Training set & 80\% & 6556 \\ Validation set & 10\% & 820 \\ Test set & 10\% & 820 \\ Total & 100\% & 8206 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Training, validation and test data sets.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Data Source** & **Total** & **After Clipping** & **Positive** & **Negative** \\ \hline Manual shooting & 458 & 1294 & 670 & 624 \\ Drone shooting & 218 & 912 & 450 & 462 \\ Internet search & 2000 & 2000 & 1000 & 1000 \\ Public data set & 4000 & 4000 & 2000 & 2000 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Dataset information.  
describe the number or occupancy rate of each grayscale pixel in the image matrix, that is, the number of pixels corresponding to each gray level between 0 and 255 is counted.  
Linear transformation is used to enhance contrast, which is a less computationally intensive method of enhancing dynamic range by linearly stretching the original gray level to stretch the range of the original gray level through linear transformations. The Equations (2)-(4) of a linear transformation are shown below.  
\[\mathrm{g(f)=af+b,[s_{1},s_{2}]\rightarrow[t_{1},t_{2}]} \tag{2}\]  
\[\mathrm{g(f)=(f-s_{1})\times(t_{2}-t_{1})\times(s_{2}-s_{1})+t_{1}} \tag{3}\]  
\[\mathrm{a=\frac{(t_{2}-t_{1})}{(s_{2}-s_{1})},b=t_{1}-s_{1}\cdot(t_{2}-t_{1}) \cdot(s_{2}-s_{1})} \tag{4}\]