# Autonomous Prostate Segmentation in 2D B-Mode Ultrasound Images
## 4 Superpixel Algorithm Incorporating Image Statistics
### Superpixel Algorithm Outline
#### 4.3.2 Region Update
From empirical observation, however, it is advantageous to limit the number of unions performed during one algorithm iteration. This allows more time for the pixel cluster layer to converge, where the base SLIC algorithm in [31] was shown to require a number of iterations before satisfactory cluster convergence. For this work, a subset of all of the regions is evaluated for union operations in each iteration. The subset of regions to analyze was chosen to encourage regions to grow in size and to guarantee that small regions, those with an area less than \(r_{min}\), had a union performed on them. To do this, the size values \(n_{kpx}\) in the superpixel region list \(\mathbf{R}\) were sorted such that the smallest regions are investigated first. A limit, \(n_{union}\), was placed on the number of unions performed at each iteration and, empirically, the superpixels were found to converge well when \(n_{union}=50\) regions per iteration. Using the list of region indexes sorted according to size, all regions smaller than \(r_{min}\) are evaluated. If removing those small regions does not exceed the \(n_{union}\) unions-per-iteration limit, then the algorithm continues working through the sorted list to evaluate regions until \(n_{union}\) union operations have been performed. This ensures all regions have an area larger that \(r_{min}\) while achieving adequate convergence of the pixel clusters and growth of the superpixel regions. _Cluster Merge:_  
After the cluster update and region union operations, the optimization constraints for the pixel cluster size \(c_{min}\) and number of clusters per region \(c_{max}\) must be enforced. After the region union procedure, all regions smaller than \(r_{min}\) are placed into nearby regions and the following cluster merge operation works on the pixel cluster components inside of the updated regions. Regions may also now contain more than the maximum allowable number of clusters, which will be corrected through the use of the cluster merge operation. In a similar manner to the region update method, the cluster merge method works to join together neighbouring pixel clusters to create new, larger, and contiguous pixel clusters. The cluster merge operation respects the pixel cluster-superpixel region hierarchy, such that a pixel cluster belongs only to a single region, and the merge operation does not move clusters between regions. The cluster merge update loops through all of the individual pixel clusters, \(C_{j}\), with the size of the cluster, \(n_{jpx}\), being calculated. Any regions smaller than \(c_{min}\) are merged with their nearest neighbouring clusters inside of their respective regions. The neighbours of a cluster \(C_{j}\) belonging to a region \(R_{k}\) are defined to be all of the other clusters within that region, \(\left\{C_{i}\in R_{k}\
eq C_{j}\right\}\). The nearest neighbour to the cluster \(C_{j}\) is defined as the neighbouring cluster with the minimum Euclidean distance between their respective centroids,  
\[N_{N}(C_{j})=\min_{i}\sqrt{(x_{j}-x_{i})^{2}+(x_{j}-x_{i})^{2}}\forall C_{i} \in R_{k}\
eq C_{j}, \tag{43}\]  
Figure 7: Union on yellow superpixel regions, showing regions and connections before and after operation. (**a**) Superpixel regions before union operation; (**b**) Superpixel region after union operation. where \(x_{i},x_{j},y_{i}\), \(andy_{k}\) are pixel coordinates of the centroids, and \(N_{N}(C_{j})\) returns the index \(i\) of the nearest neighbour to \(C_{j}\). The merge operation is performed by updating the label image \(\mathcal{L}(i)\) such that,  
\[\mathcal{L}(j)=i,\;\forall\;\text{pixels}\;j\in C_{j}, \tag{44}\]  
which relabels all of the pixels in the cluster \(j\in C_{j}\) to belong to the cluster \(C_{i}\). Lastly, the row \(j\) in the pixel cluster list \(\mathcal{C}\) and the pointer \(j_{k}^{*}=j\) in the parameters of region \(R_{k}\) are then removed.