# STAVOS: A Medaka Larval Cardiac Video Segmentation Method Based on Deep Learning
## 3 Methods
### Automation System  
In order to further reduce manual operations, we have developed a deep learning-based system for the precise segmentation of medaka ventricles. This system can automatically compute relevant parameters of the medaka heart and provide visualizations of changes in ventricular status.  
The overall workflow of the system is illustrated in Figure 3. To operate the system, users only need to provide a video recording of medaka heartbeats and mark the true mask region of the central ventricle in the STA frame, which is automatically computed by the system. Subsequently, the system automatically loads and reads the medaka heartbeat video and the STA frame's mask. Utilizing the optimal weights obtained through training the STAVOS model, the system infers the ventricular regions for all frames in the video. In the images, the medaka ventricle is represented as a closed region. Based on the precise segmentation of the ventricles of the medaka, we can accurately calculate data such as the diameter and area of the ventricles. The size of the closed region undergoes periodic changes with the heartbeat, with the process from large to small defined as systole (S) and from small to large as diastole (D). The moment of maximal closure is defined as end-diastole (ED), and the moment of minimal closure is defined as end-systole (ES). A complete cardiac cycle consists of one systole and the adjacent diastole; thus, the time of one heartbeat is the time between two adjacent EDs or two adjacent ESs. Time is represented by the number of frames in the video. Therefore, the formula for heart rate is as follows:  
\[HR=\frac{fps}{ESF_{c}-ESF_{p}} \tag{7}\]Here, \(ESF_{c}\) represents the current end-systolic frame, and \(ESF_{p}\) represents the previous end-systolic frame.  
Fractional shortening (FS) is a metric used to evaluate cardiac contractile function, reflecting the heart's ability to contract by measuring the change in ventricular diameter between diastole and systole. The calculation formula is expressed as follows:  
\[FS=\frac{D_{d}-D_{s}}{D_{d}}\times 100\% \tag{8}\]  
Here, \(D_{d}\) represents the short-axis diameter at end-diastole, and \(D_{s}\) represents the short-axis diameter at end-systole (ES).  
By assuming a prolate spherical shape for the ventricle, the following volume formula can be used:  
\[V=\frac{4}{3}\pi\times\frac{DL}{2}\times\frac{DS}{2} \tag{9}\]  
where \(DL\) and \(DS\) are the long and short-axis diameters of the closed region, respectively.  
Ejection Fraction (EF) is a critical indicator for assessing cardiac pumping efficiency, with its value reflecting the strength of cardiac function. The calculation formula is as follows:  
\[EF=\frac{EDV-ESV}{EDV}\times 100\% \tag{10}\]  
where \(EDV\) is the volume at \(ED\), and \(ESV\) is the volume at \(ES\). Due to the impracticality of measuring ventricular volume through a single-angle 2D video, researchers commonly employ the aforementioned methods to calculate ventricular parameters.  
In addition to generating a table of relevant parameters for the medaka ventricle, the system also produces a GIF illustrating the shape of the medaka ventricle, an electrocardiogram (ECG) GIF, and a 3D dynamic simulation GIF of the heartbeat. This allows users to gain a more visual understanding of the changes in ventricular status.