## 3 Implementation of Digital Image Processing Based on Particles Statistical  
The observed porosity was obtained by digital image processing and the analysis of the sand at the surface under a certain observation depth. When counting the number of target particles in a digital image, the target particle appeared in the digital image as an independent connected domain if it was a single particle, which could be easy to be identified, as shown in Figure 2b. When sand particles blocked each other in the observation direction, there was a connected domain containing overlapping projection areas of multiple target particles in digital images, as shown in Figure 3a. According to the definition of observed porosity, this connected domain needed to be distinguished. In this  
Figure 2: Two types of the dimensionality reduction processes for sand particles: (**a**) terrain image; (**b**) binary image. study, the k-means clustering algorithm was used to determine the number of centroids based on the particle size of target particles. [PERSON] et al. [33] proposed the k-means clustering algorithm in 1979, and it has been continually improved since then [34]. So far, it has been widely used as a classical algorithm. The main idea is to use distance as the evaluation index of similarity; that is, the closer the two objects are, the more similar they are. The method was used here with each pixel of a connected domain as the object and the centroid as the clustering center, and the average pixel of the target particle was taken as the criterion to distinguish the type and number of connected domains, which were analyzed by comparing the distances between each pixel in the connected domain and the centroid. The specific steps for using k-means clustering algorithm are as follows:  
1. The digital image was captured by a camera, and the binary image of target particles was obtained through the image pre-processing, such as the binarization transformation under specific thresholds, as well as the expansion and corrosion operation in morphology, which are used to remove the pores formed by small particles blocking the target particles, which will not be elaborated here. Figure 3b shows a binary image of two particles in Figure 3a. 2. The image's connected domain and related information were obtained, and then, the initial centroid number k was determined by the number of pixels in each connected domain. And based on the number of pixels, the number of initial centroids was calculated. The initial centroid location was selected arbitrarily. As shown in Figure 3b, the initial centroid number of k = 2 was determined by dividing the number of pixels in the connected domain by the number of one-particle pixels, which is in a certain range and can implemented by a loop in the program. And the result was between 1 and 2 times the average number of target pixels. 3. The distance between all of the pixels of target particles and the position of the initial centroid was calculated, as shown by \(R_{1}\) and \(R_{2}\) in Figure 3b. According to the principle of the shortest distance from the centroid, all of the pixels were classified into two categories, as shown in the oblique shaded area and the blue area in Figure 3c. Here, the Euclidean distance is used for calculating distance, rather than other distances such as the Minkowski distance, for the shape of sand particles approaching a sphere. 4. The center point moves to a new center point position, which is the position of the average distance calculated in the case of the previous cluster center, as shown in Figure 3c. 5. Steps 2 and 3 were repeated until the centroid no longer needed to be moved. The final centroid was taken as the center, and the pixel from which the smallest distance was taken as the target particle. During the above iterative steps, the sum of the squared error (SSE) was also calculated to determine the quality of the cluster assignments.