# Automated Ground Truth Generation for Learning-Based Crack Detection on Concrete Surfaces
## 2 Proposed Method
### First-Round GT Generation
#### 2.1.2 Crack Pixel Segmentation  
Intuitively, edge points often appear around cracks, and the different intensities of the grayscale represent different levels of discontinuities. Hence, a typical edge detection filter, i.e., the Sobel operator, is applied to image \(I_{\text{e}}\). The Sobel operator uses a pair of kernels, \(S_{x}\) and \(S_{y}\), as presented in (1), to calculate the approximations of the derivatives in the \(x\)- and \(y\)-axes, respectively. \[S_{x}=\left[ \begin{array}{ccc}1&0&-1\\ 2&0&-2\\ 1&0&-1\end{array} \right]\text{ and }S_{y}=\left[ \begin{array}{ccc}1&2&1\\ 0&0&0\\ -1&-2&-1\end{array} \right]. \tag{1}\]  
On the basis of the results of employing these two kernels convolved with \(I_{\text{e}}\), the resulting gradients along the two axes, \(G_{x}\) and \(G_{y}\), are further combined to form the magnitude and direction angle, as calculated using (2) and (3). \[Mag=\sqrt{\left(S_{x}*I_{\text{e}}\right)^{2}+\left(S_{y}*I_{\text{e}}\right) ^{2}}=\sqrt{\left(G_{x}\right)^{2}+\left(G_{x}\right)^{2}} \tag{2}\]  
\[\Theta=\tan^{-1}\left(\frac{G_{y}}{G_{x}}\right) \tag{3}\]  
Subsequently, the magnitude image is obtained via a thresholding process such that the pixels whose intensity is less than a predefined threshold \(T_{\text{mag}}\) become zero. The thresholding used in this study is presented in (4). \[Mag(x,y)=\left\{ \begin{array}{rl}Mag(x,y),&\text{if }Mag(x,y)\geq T_{\text{mag}}; \\ 0,&\text{otherwise},\end{array} \right. \tag{4}\]  
where \(Mag(x,y)\) is the intensity at pixel \((x,y)\) in the magnitude image, and \(T_{\text{mag}}\) is a predefined threshold. Subsequently, the well-known morphological closing operation with a filter size of \(N\times N\) is performed on this thresholded image to fill the cracks. Figure 2 shows the result of thresholding the magnitude image and the result obtained after performing the closing operation. In this study, we set the kernel size of closing operation \(N=15\), which is sufficiently large to connect the edge points to form connected components in the image. As shown in Figure 2b, the approximate crack shape can be extracted. Figure 1: An example of edge pixel enhancement: (**a**) the original color image; (**b**) result of edge pixel enhancement. Thus far, the crack is outlined roughly. Furthermore, a more accurate label needs to be drawn to form the GT. As shown in Figure 1, the crack can be considered the foreground, whereas the flat concrete surface is the background. GrabCut [31] is an iterative image segmentation method inspired by the graph cut algorithm [32] and involves simple user interactions. The simplest method to interact with a user is by drawing a rectangle to bound the desired object. Because the crack object has been extracted, as shown in Figure 2b, the main task is to identify a rectangle to enclose the bright connected objects by excluding noise. Using the well-known connected-component labeling (CCL) method, we can locate a significant portion of the crack by a bounding box. Figure 3 presents the CCL results of Figure 2b, and the same bounding box drawn in Figure 1a. It is noteworthy that the nearby bounding boxes were merged and only the bounding boxes whose width (or height) exceeded \(w/3\) (or \(h/3\)) were preserved. In this study, we employed only the hard segmentation of the GrabCut algorithm because the crack boundary typically contains high-intensity discontinuities. On the basis of the bounding box shown in Figure 3b, we implemented the GrabCut algorithm within an image as follows:  
Step 1: Generate an initial trimap using the bounding box. The trimap \(T=\{T_{\text{B}},\ T_{\text{F}},T_{\text{U}}\}\), where \(T_{\text{B}}\), \(T_{\text{F}}\) are background and foreground regions, respectively, and \(T_{\text{U}}\) is the unknown region. In this initialization step, only \(T_{\text{B}}\) was provided. The pixels outside the rectangle were marked as the background, and the foreground was set to empty, i.e., \(T_{\text{F}}=\phi\).