## 3 Materials and Methods
### Watershed Segmentation  
The watershed transform is an image processing technique that can be applied to a binary image for object segmentation. In the segmented images of nucleus tissue components, we observed that there were many overlapping cell nuclei. We separated these connected objects by applying the watershed segmentation algorithm [20; 21]. This method was used to extract nucleus-based morphological features for SVM classification. We validated this algorithm experimentally and found that it performs better than other cell nuclei separation algorithms. It is one of the well-known methods for separating overlapping objects [22]. Figure 3: Image segmentation using K-means algorithm: (**a**) original tissue image; (**b**) lumen segmentation; and (**c**) nucleus segmentation. Algorithm for Watershed Segmentation  
According to the algorithm, \(g(x,\ y)\) and \(M_{i}\) is the image pixel value and the regional minima, respectively. The iteration steps of the algorithm are as follow:  
\[T[n]=\{(x,\ y)\ \big{|}\ g(x,\ y)<n\} \tag{3}\]  
\[n=min+1\ \text{to}\ n=max+1 \tag{4}\]  
\[C_{n}(M_{n})=C(M_{i})\cap T[n] \tag{5}\]  
where \(T[n]\) is the set of coordinates of a point in \(g(x,\ y)\), \(n\) is the flooding stage, and \(C_{n}(M_{i})\) is the set of coordinates of points in the catchment basin. \[C_{n}(M_{n})=1,\ \text{at}\ (x,\ y);\text{if}\ (x,\ y)\in C(M_{i})\ \text{and}\ (x,\ y)\in T[n] \tag{6}\]  
\[C_{n}(M_{n})=0,\text{\emph{otherwise}} \tag{7}\]  
We computed the results of the above two equations and viewed the resulting binary image. \[C[n]=\bigcup_{i=1}^{R}C(M_{i}) \tag{8}\]  
\[C[max+1]=\bigcup_{i=1}^{R}C(M_{i}) \tag{9}\]  
where \(C[n]\) is the union of the flood catchment basin portions at stage set \(n\), \(C[max+1]\) is the union of all catchment basins. As per Equations (8) and (9), \(C[n]\) is the subset of \(T[n]\) and \(C[n-1]\) is the subset of \(C[n]\). Hence, each connected component of \(C[n-1]\) is the connected in exactly one connected component of \(T[n]\). We used the following steps to separate overlapping nuclei:  
1. Converted 24-bit/pixel RGB color image to binary using adaptive thresholding method. 2. Removed the noise from the binary image. 3. Applied the Euclidean distance transform to a binary image to generate a distance map. 4. Used a Gaussian filter to smooth the distance map. 5. Applied inverse distance transform after smoothing the distance map. 6. Identified local minima using markers on the inverse distance transform image. 7. Finally, applied watershed segmentation based on local minima points, iterating until all overlapping objects were segmented. We used the described watershed segmentation algorithm to separate the overlapping cell nuclei. This has been used previously for nucleus counting and to extract features for classification [23]. Figure 4 shows the necessary steps for watershed segmentation, including segmenting the nuclei image, converting to a binary image, applying the Euclidean distance transform, and labeling the watershed image using color mapping. However, at the beginning of the watershed segmentation, there were some errors leading to over-segmentation, which caused some objects to be divided into several parts, as shown in Figure 5a. To show an example of over-segmentation, we used a cropped image that was taken from the region marked with a red box in Figure 4. First, to control over-segmentation, we used an approach called the marker-selection watershed transform to improve the segmentation results [24]. This approach determines markers for each region of interest and transforms the distance map image in such a way that the region markers are the only local minima of the resulting image. Second, after the Euclidean distance transform, we applied a Gaussian filter to smooth the distance map and then applied internal markers to the smoothed inverse results of the distance transform, as shown in Figure 5b. Third, the watershed algorithm was applied to the marker selection image, as shown in Figure 5c.