# Autonomous Prostate Segmentation in 2D B-Mode Ultrasound Images
## 4 Superpixel Algorithm Incorporating Image Statistics
### Superpixel Regions  
The input image pixels are now grouped into SLIC style clusters, as proposed in [31], through the creation of the label image. We now propose our extension to the SLIC superpixel algorithm with a second optimization layer. This additional layer is the mechanism through which image statistics will be incorporated into the superpixel algorithm. The underlying implementation of the second layer incorporates a graph component, which will allow for the output of the superpixel algorithm to be segmented by graph cutting in a straightforward manner. The components of this second layer will be referred to as superpixel regions, which will be stored in a list \(\mathbf{R}\), given by  
\[\mathbf{R}=[R_{0},R_{1},...,R_{n}]^{\top} \tag{26}\]  
with \(R_{k}\) denoting the individual regions. In a similar manner to a pixel cluster, \(C_{j}\), being composed of a number of individual pixels, a region \(R_{k}\) is composed of a number of pixel clusters (\(C_{j}\)), thus building a second optimization layer on top of the pixel clusters. This second layer creates a pyramid-type hierarchy in this superpixel implementation, as diagrammed in Figure 5.  
Each region consists of a series of calculated values, given by  
\[R_{k}=[\mathbf{\hat{F}_{k}},x_{k},y_{k},j_{k}^{\star}], \tag{27}\]  
where \(j_{k}^{\star}\) is the list of indexes to the pixel clusters (\(C_{j}\)) which make up the superpixel region, \((x_{k},y_{k})\) is the centroid of the region, and \(\mathbf{\hat{F}_{k}}\) is the empirical cumulative density function (CDF) of all of the pixels contained within the region. As a region is made up of a number of pixel clusters, all of the pixels belonging to the region's subordinate clusters are defined to be pixels of the region. Formally, this is described as the union of all of the pixels in the component clusters of \(R_{k}\), given as  
\[i\in R_{k}=\bigcup_{j\in k}i\in C_{j}, \tag{28}\]  
where \(j\in R_{k}\) are the component clusters of the region. The centroid values of the region, \(x_{k}\) and \(y_{k}\), are calculated as follows:  
\[ \begin{split} n_{kpx}&=\sum_{j\in R_{k}}n_{jpx}\\ x_{k}&=\sum_{j\in R_{k}}\frac{n_{jpx}\cdot x_{j}}{ n_{kpx}}\\ y_{k}&=\sum_{j\in R_{k}}\frac{n_{jpx}\cdot y_{j}}{ n_{kpx}},\end{split}  \tag{29}\]  
with \(n_{jpx}\) being the number of pixels in a cluster and \(n_{kpx}\) being the total number of pixels within the region. The empirical CDF, \(\mathbf{\hat{F}_{k}}\), allows for a metric based on pixel intensity (image) statistics within a region; the CDF is calculated through  
\[ \begin{split}\hat{F}_{k}(x)&=\text{Count}(\mathcal{ L}(i\in R_{k})\leq x)\\ \mathbf{\hat{F}_{k}}&=[\hat{F}_{k}(0),\hat{F}_{k}(1 ),...,\hat{F}_{k}(255)],\end{split}  \tag{30}\]  
given a counting function, \(\text{Count}()\), which returns the number of pixels within a set, in this case, the set of pixels in the region \(R_{k}\) with an intensity value, \(\mathcal{L}(i)\), less than \(I\). This is essentially the cumulative summation of all the elements in the image intensity histogram, for all of the pixels in the region \(i\in R_{k}\). Figure 5: Hierarchy created by the superpixel algorithm, showing individual pixels, pixel clusters (\(C_{1},C_{2},C_{3},C_{4},C_{5}\), and \(C_{6}\)), and superpixel regions (\(R_{1},R_{2}\), and \(R_{3}\)), where the regions are the graph vertices interconnected with graph edges. The superpixel region optimization uses a graph-based component, \(\mathcal{G}\), to keep track of which regions are adjacent to one another, called neighbours. For this work, an undirected graph of the form  
\[\mathcal{G}=\{\mathcal{V},\mathcal{E}\}, \tag{31}\]  
is used. Here, \(\mathcal{V}\) are the vertices of the graph which are interconnected by edges \(\mathcal{E}\).