## 3 Methods  
### Image Segmentation Based on Two-Level Clustering  
The main differences between maceral groups are the gray scale values. Generally, the gray scale values of liptiinite, vitrinite and inertinite decrease successively, as demonstrated in Figure 2a. The gray scale distribution curves illustrate that there are noticeable differences among three maceral groups and the binder. However, it is difficult to define the boundaries between them. In addition, the boundaries corresponding to different photographs are different. The gray scale range of each maceral group varies with the degree of coalification. Figure 2b shows the distribution of gray scale values of binder and inertinite across four photomicrographs. It can be seen that the gray range of binder is relatively fixed, whereas that of inertinite group of 4 coal samples differs greatly. Therefore, it is unreliable to adopt a fixed threshold to segment microscopic photographs with different coalification degrees.  
Figure 1: Examples of maceral components and binder. Each row represents a class. They are binder, vitrinite, fusinite, semifusinite, cutinite, sporinite and inerteddetrinite from top to bottom respectively. The black color areas (i.e., RGB value = 0) in each figure represent the background of the given maceral component. The micrinite is not shown here for its small size accounting for only a few pixels.  
Figure 2: Comparison of gray scale distributions corresponding to different maceral groups and the binder. (**a**) Gray scale distributions of maceral groups and the binder in one coal sample; (**b**) the difference in the gray scale distributions across 4 coal samples. For simplicity, we only show the curves corresponding to binder and inertinite in (**b**).  
In order to automatically detect the boundaries of each maceral, we employed image-wise segmentation which is able to divide each microscopic image into a sequence of discrete regions, each having similar attributes. It is an essential step for further maceral composition analysis. Considering the fact that the maceral components within each group mostly are not adjacent to each other and the gray scale values are the major difference between maceral groups, we adopt the gray scale values of each pixel as the features. K-means clustering, one of the most favorable clustering techniques, is utilized for its simplicity and computational efficiency [21; 22].  
The main steps of K-means algorithm can be summarized as follows:  
(1) Choose initial cluster centroids \(\mu_{1},\mu_{2},\mu_{3},\ldots,\mu_{k}\in R^{d}\) randomly, where \(k\) represents the number of clusters and \(d\) represents the dimension of the feature space.  
(2) Repeat until convergence:  
For each pixel \(p\), assign it to its nearest centroid,  
\[c^{p}:=\underset{j}{\text{argmin}}\|\mathbf{v}^{p}-\mu_{j}\|^{2} \tag{1}\]  
Update each centroid,  
\[\mu_{j}:=\frac{\sum\limits_{i=1}^{M}1[c^{p}=j]\mathbf{v}^{p}}{\sum\limits_{i= 1}^{M}1[c^{p}=j]} \tag{2}\]  
where \(c^{p}\) represents the cluster of pixel \(p\), \(\mathbf{v}^{p}\) is a vector consisting of RGB value of pixel \(p\), and \(M\) represents the total number of pixels in each photomicrograph, respectively.  
In addition, due to the complexity of coal properties, it is difficult to achieve accurate clustering results by using single-level clustering only. Single-level clustering is difficult to provide satisfactory segmentation results. Hence, a coarse-to-fine strategy is adopted. In the coarse clustering level, the regular K-means clustering algorithm is first applied to get rough clustering results, which splits a whole image into two sub-clusters. In the fine clustering level, each of the previous clusters is partitioned again into two fine sub-clusters (i.e., maceral groups and binder).