# Unsupervised Image Segmentation on 2D Echocardiogram
## 3 Methods
### Performance Evaluation
#### 3.5.2 Quantitative Evaluation and Mask Extraction  
Following the visual inspection, after the model was fully trained, we performed a quantitative evaluation using the segmented left ventricles. With the segmented left ventricle, we computed the Dice coefficient and Intersection over Union (IoU) to assess the segmentation accuracy, comparing our method against the ground truth and benchmarking it with the EchoNet-Dynamic model. The ground truth (GT) masks were generated through a semi-automated process based on expert annotations of the heart chambers at various points in the cardiac cycle. These tracings, representing the left ventricle's endocardial borders, were used to create binary masks by filling the contours of the traced polygons. This process allowed for accurate delineation of the ventricular boundaries based on expert input and followed the same approach used by [PERSON] et al. (2017). In contrast, the masks produced by the EchoNet Dynamic model were extracted from its predicted segmentation output. Specifically, the left ventricular mask was represented by a red pixel value (R = 255, G = 1, B = 1) in the top-right quadrant of the predicted video. The extraction process involved isolating this region and applying morphological operations to fill any gaps. The results obtained through this mask extraction were highly consistent with those reported in the original EchoNet Dynamic paper (2017), confirming that our extraction method accurately replicates the model's intended performance. In addition to segmentation accuracy, we calculated the ejection fraction (EF) from the segmented volumes of the left ventricle and compared it to the ground truth EF values. To ensure a fair comparison, we used the same test set (filtered by our quality assessment criteria) when comparing with the EchoNet model. This approach resulted in minor differences in the final results, as EchoNet's calculations averaged EF over multiple frames, whereas we calculated EF using only two frames: one in the diastolic position and the other in the systolic position, as specified in the ground truth. The Dice and IoU values are calculated using the following formulas:  
* Dice Coefficient (Dice) is given by: \[\text{Dice}=\frac{2\cdot|A\cap B|}{|A|+|B|}\] where \(A\) represents the predicted segmentation and \(B\) corresponds to the ground truth. The Dice coefficient measures the overlap between the predicted and ground truth segments, with a value of 1 (100%) indicating perfect overlap. * Intersection over Union (IoU), also known as the Jaccard Index, is defined as: \[\text{IoU}=\frac{|A\cap B|}{|A\cup B|}\] IoU measures the ratio of the intersection to the union of the predicted and actual segments, providing a stricter evaluation than Dice. For evaluating EF, we computed the Mean Absolute Error (MAE), the Mean Absolute Percentage Error (MAPE), and the Root Mean Squared Error (RMSE) between the EF estimated by our method and the ground truth as:  
\[\text{MAE}=\frac{1}{n}\sum_{i=1}^{n}|y_{i}-\hat{y_{i}}|\]  
\[\text{MAPE}=\frac{100\%}{n}\sum_{i=1}^{n}\left|\frac{y_{i}-\hat{y_{i}}}{y_{i }}\right|\]\[\text{RMSE}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_{i}-\hat{y}_{i})^{2}}\]  
where \(y_{i}\) is the ground truth EF value, and \(\hat{y}_{i}\) is the predicted EF value. MAE measures the average magnitude of the errors in a set of predictions, without considering the direction of the errors (whether they are over- or under-estimated). Lower MAE values indicate better model accuracy. MAPE is similar to MAE but expresses the error as a percentage of the true value, making it scale-independent and easier to interpret across different ranges of EF values. This is particularly useful when comparing predictions across different patients or EF ranges, as it allows for a direct understanding of the relative size of the error. MAPE is a preferred metric when comparing models across datasets or when the magnitude of the values varies significantly.