## 3 Image Processing
### K-Means Clustering  
K-means clustering is one of the most famous unsupervised learning methods [40]. K-means clustering aims to partition unlabeled data into K clusters using the distance between each pair of data, and the cluster to be included is determined to minimize the mean distance in each cluster. Given a set of data \(\textbf{x}=\{x_{1},x_{2},\cdots,x_{k}\}\) where each data has the dimension, K sets \(S=\{\text{S}_{1},\text{S}_{2},\cdots,\text{S}_{k}\}\) are determined to minimize the within-cluster variance as  
\[\underset{\textbf{S}}{\text{argmin}}\sum_{i=1}^{K}\sum_{x\in S_{i}}\|\textbf{ x}-\mu_{i}\|^{2}=\underset{\textbf{S}}{\text{argmin}}\sum_{i=1}^{K}|S_{i}|Var(S_{i}) \tag{1}\]  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Step** & **Operation** \\ \hline
1 & K-means Clustering: Divide original image into three images according to color similarity \\ \hline
2 & Convert original image into gray-level image \\ \hline
3 & Subtract median-filtered image from original gray-scale image to remove background \\ \hline
4 & Remove image parts according to structural joints, sediments, etc. using segment information \\  & obtained by k-means clustering \\ \hline
5 & Binarization using [PERSON]’s method (threshold = 0.2 \(\times\) [PERSON]’s threshold) \\ \hline
6 & Morphological closing to connect slightly-separated pixels \\ \hline
7 & Remove blobs (i.e., pixel groups) with the controlled area and eccentricity \\ \hline \hline \end{tabular}
\end{table}
Table 1: Seven image processing steps for the crack detection.  
Figure 2: The depth first (DF)-representation of the octree data structure.  
where \(\mu_{i}\), \(|S_{i}|\), \(Var(S_{i})\) denote mean value (i.e., centroid), count, and variance of data in \(S_{i}\), respectively. Based on the law of total variance [49], the minimizing the within-cluster variance equals to maximizing the out-of-cluster variance.  
The basic algorithm of K-means clustering starts from selecting K points as the initial centroids. Then the K clusters are initially formed by assigning all points to the closest centroid and the centroid of each cluster is computed. Then reforming of K clusters and recomputing the centroid of each reformed cluster is repeated until the centroids do not change.  
In the image processing, the data corresponds to the color vector in each pixel, and the Euclidean distance of the color vector represents the dissimilarity of the colors of the pixels. By applying K-means clustering, the image can be segmented into K pieces of pixels according to their color similarity corresponding to the concrete surface conditions. Figure 3 shows an example of image segmentation by K-means clustering. The original image in Figure 3a is segmented into three differently colored images in Figure 3b. The blue segment (BS) illustrates the background, and the green segment (GS) illustrates the concrete surface. Notably, the red segment (RS) highlights the sediments and structural joints that are generally dark-colored in the original image, even compared to the cracks on the concrete surface. Since the sediments and structural joints are the biggest impediments in identifying cracks from the images, the third segments obtained at this step will be used in Step 4 to tweeze out the impediment for successful image processing.