# Unsupervised Image Segmentation on 2D Echocardiogram
## 3 Methods
### Post-Processing Through 3D Watershed Segmentation  
After obtaining the initial segmentation from the U-Net model, we apply a post-processing step using the 3D Watershed algorithm to isolate the left ventricle in the echocardiogram images. This step is essential because the U-Net output includes both the heart walls and chambers, necessitating further refinement to focus solely on the left ventricle. Additionally, due to the nature of the similarity loss function, the number of segmentation masks tends to decrease as the training progresses. This reduction was observed during our testing, as shown in Figure 4. While this effect demonstrates promising segmentation of the heart walls, it necessitates additional processing to accurately extract the chamber volumes, such as the left ventricle, for instance-specific measurements. The Watershed3D algorithm is particularly suited for this task due to its ability to handle complex 3D structures and provide precise segmentation boundaries. Unlike traditional contour-based methods, such as active contours or snakes, Watershed3D excels in environments with significant noise and overlapping structures, which are common in echocardiographic images. The algorithm works by treating the intensity values of the image as a topographical surface and simulates the flooding of this surface from local minima. The points where the floods meet define the segmentation boundaries [25]. Figure 4: Reduction in the number of segmentation masks as training progresses, illustrating the refinement in segmentation and the need for additional processing to extract chamber volumes. Figure 3: Training and validation loss over epochs, highlighting the smallest losses for both training and validation at epoch 32. The model was saved at this point, as it achieved the best validation loss of 0.0602. The key steps in the 3D Watershed algorithm for isolating the left ventricle from the echocardiographic images are as follows:  
* Gradient Computation: The first step involves computing a gradient of the image to highlight regions of rapid intensity changes, which will serve as potential boundaries. This gradient map is combined with a positional bias that accounts for the spatial position of the pixels within the image, ensuring that the algorithm can handle complex 3D structures in a volumetric image. * Thresholding and Mask Creation: A binary mask is generated for each frame using [PERSON]'s thresholding technique, which automatically separates the foreground and background by selecting an optimal threshold that minimizes the variance within each group. This technique analyzes the histogram of pixel intensities in the gray-scale image, determining a threshold that best distinguishes between the two regions. After applying the threshold, all pixels below the threshold are classified as background, and those above as foreground. The mask is then inverted, as we are interested in using the background areas to initiate the watershed flooding process. * Positional Bias and Distance Transform: In addition to the standard distance transform, a positional bias is introduced. This bias is weighted across axes as follows: 0.4 for the \(z\)-axis, 0.3 for the \(y\)-axis, and 0.3 for the \(x\)-axis. This helps prioritize certain axes when calculating the distances, leading to improved segmentation accuracy for 3D data. \[D(x)=\min_{y\in B}\|x-y\|\] where \(D(x)\) represents the distance transform at point \(x\) of the non-background structures, and \(y\) is a point in the background \(B\). The Watershed algorithm then operates on the negative of this distance map, effectively segmenting regions based on local minima. * Marker-Based Segmentation: To control the flooding process, we use markers that identify regions of interest such as the left ventricle. These markers are derived from the U-Net's initial segmentation output and refined with the computed distance transform.