# Autonomous Prostate Segmentation in 2D B-Mode Ultrasound Images
## 4 Superpixel Algorithm Incorporating Image Statistics
### Superpixel Algorithm Outline
#### 4.3.2 Region Update
The KS test has several useful properties, in that it is symmetric \(D_{KS}(\hat{F}_{i}(x),\hat{F}_{j}(x))\equiv D_{KS}(\hat{F}_{j}(x),\hat{F}_{i}( x))\) and does not require the data to be modelled as belonging to some underlying distribution. The symmetry property of the KS test allows for the distance values to be evaluated only once per graph edge irrespective of the order of elements in an edge \(E_{v}\). The second property, the independence from an underlying distribution, is critical in the context of ultrasound image processing as the pixel intensities seen in B-mode images have been shown to follow a number of different statistical distributions varying with tissue type, location in the body, ultrasound intensity, and transducer focusing [39]. A low KS score between two regions indicates that they are statistically similar. In a loop, each region \(R_{k}\) and its neighbours \(R_{m}\in\mathcal{N}_{k}\) will be compared to see if they are statistically similar enough, and if so, a union operation will be performed. For each \(R_{k}\), the neighbour with the minimum KS distance,  
\[D_{KSmin}(R_{k})=\min_{k_{m}}D_{KS}(k,k_{m})\forall k_{m}\in\mathcal{N}_{k}, \tag{40}\]  
giving the index \(m\) of the neighbouring region \(R_{m}\) with the minimum statistical difference \(D_{KSmin}(R_{k})\) to \(R_{k}\) is identified. A binary threshold is then used to determine if a union will be performed:  
\[R^{\prime}_{k}=R_{k}\cup R_{i}\text{ if }\Big{(}D_{KSmin}(k)\leq\lambda_{KS} \text{or}n_{kpx}<r_{min}\Big{)}, \tag{41}\]  
which results in a new region \(R^{\prime}_{k}\) when \(R_{k}\) and \(R_{m}\) are either similar to one another, or forcing a union, when the area of \(R_{k}\) is smaller than the minimum allowable region size \(r_{min}\). When \(n_{kpx}\geq r_{min}\), the threshold \(\lambda_{KS}\) prevents unions between statistically dissimilar regions. If neither condition is met, then \(R_{k}\) will be ignored and the next region in the set \(\mathbf{R}\) will be tested. When either of the the union conditions are met, the union results in the two regions being combined to create one larger region; \(R^{\prime}_{k}=R_{k}\cup R_{m}\). This new region, \(R^{\prime}_{k}\), takes ownership over all of the pixel clusters that originally belonged to \(R_{k}\) and \(R_{m}\). From (27), the region is described by its parameters, \(R^{\prime}_{k}=[\hat{\mathbf{F}}^{\prime}_{\mathbf{k}},x^{\prime}_{k},y^{ \prime}_{k},y^{\prime*}_{k}]\). The indexes for the all of the pixel clusters in this new region, \(j^{\prime*}_{k}\), are given by  
\[j^{\prime*}_{k}=j^{*}_{k}\cup j^{*}_{m}, \tag{42}\]  
where \(j^{*}_{k}\) are indexes for the clusters \(\{C_{j},j\in R_{k}\}\) and, likewise, \(j^{*}_{m}\) are indexes for the clusters \(\{C_{j},j\in R_{m}\}\). The values in the rest of \(R_{k}\) are then updated, from (29) and (30), to incorporate all of the information from the pixel clusters in the new region. A diagram of the region union operation is given in Figure 7, where a union is performed on the two regions in Figure 7a (indicated in yellow), combining them into the single region in Figure 7b. As shown in Figure 7, after the union operation, the region list \(R\) and the adjacency graph, \(\mathcal{G}=\{\mathcal{V},\mathcal{E}\}\), need to be updated. For simplicity, the newly created region \(R^{\prime}_{k}\) will replace the parameters of \(R_{k}\) (at row \(k\)) in the region list, \(\mathbf{R}\), and the row \(m\), corresponding to \(R_{m}\), is removed from \(\mathbf{R}\). To update the graph, the \(m\) vertex \(V_{m}\) is deleted and the edge \(E_{v}=(k,m)\) is removed. Any additional edges, \(E_{v}=(k_{v1},k_{v2})\), which originally connected to \(m\), \(\{k_{v1},k_{v2}=m\}\), will be updated to connect to \(k\). Any duplicate edges in \(\mathcal{E}\) will also be cleaned up to ensure that there is only a single edge between vertices connected to one another. This procedure can continue until all of the regions \(R_{k}\) have been tested.