## 2 Materials and Methods
### ROI Selection and Heart Rate Detection  
Heart rate estimation was performed by analyzing motion within the heart region of the larvae using a frame-difference-based algorithm. Each recorded video was processed frame-by-frame to extract a fixed region of interest (ROI) around the visible cardiac area,  
Figure 1: Danionella under video recording. (**a**) is the measurement using a video camera; (**b**) is an example of an actual image.  
where blood flow can be observed. The ROI was defined based on the stationary positioning of the larvae during filming, and care was taken to ensure consistent placement across frames.  
The ROI from each frame was converted to grayscale, and its luminance change was calculated by subtracting the corresponding grayscale values from the preceding frame. To emphasize blood movement, a thresholding process was applied to the resulting difference image: pixels with a luminance change above a predefined threshold were assigned a value of 255 (white), and those below were set to 0 (black), resulting in a binary image. The sum of white pixels was then calculated for each frame, representing the extent of motion in the cardiac region.  
When the white pixel count exceeded a certain threshold, it was interpreted as one cardiac contraction. This process was repeated for each frame over the entire video sequence. For final heart rate estimation, the number of beats detected within each 10 s segment was multiplied by six to yield beats per minute (bpm).  
Let (_x_) be the grayscale intensity of the pixel at location (_x,y_) in the Region of Interest (ROI) at frame \(t\). The frame difference image (_x_) is computed as (1)-(6)  
\[D_{t}(x,y)=\mid I_{t}(x,y)-I_{t-1}(x,y)\mid \tag{1}\]  
A binary motion mask (_x_) is then computed by applying a threshold \(\theta\) to \(D_{t}(x,y)\)  
\[M_{t}(x,y)=\left\{\begin{aligned} & 1,\;if\;D_{t}(x,y)>\theta\\ & 0,\;otherwise\end{aligned}\right. \tag{2}\]  
The motion magnitude \(S_{t}\) for frames \(t\), representing the total number of pixels above the threshold, is then:  
\[s_{t}=\sum_{(x,y)\in ROI}M_{t}(x,y) \tag{3}\]  
Let \(T_{s}\) be the threshold for detecting a heartbeat (i.e., a sudden increase in \(S_{t}\)). Then, a heartbeat is detected at frame \(t\) if:  
\[Beat_{t}(x,y)=\left\{\begin{aligned} & 1,\;if\;S_{t}>T_{s}\;\;and\;S_{t-1}\;\leq T_{s}\\ & 0,\;otherwise\end{aligned}\right. \tag{4}\]  
This formula means that if the signal \(S_{t}\) exceeds the threshold \(T_{s}\), and the previous signal \(S_{t-1}\) is below the threshold, the result is 1 (event occurs); otherwise, it is 0. This allows us to count events corresponding to each heartbeat.  
The total number of beats \(B\) in a time window of \(N\) frames is:  
\[B=\sum_{t=1}^{N}Beat_{t} \tag{5}\]  
If the video frame rate is \(f\), frames per second (fps), and \(T\) is the total duration in seconds (i.e., \(N=f\cdot T\)), then the heart rate in beats per minute (bpm) is:  
\[\text{HR}_{\text{bpm}}=\frac{B}{T}\times 60 \tag{6}\]  
For example, if \(f\) is 30 fps, \(T\) is 10 s, and \(B\) is 12 beats detected, the result will be 72 bpm.  
To evaluate heart rate estimation in Danionella translucida larvae, we utilized video recordings (MP4 format, Video S1) where blood flow in the cardiac region was clearly visible. A fixed region of interest (ROI) was defined manually around the heart area, ensuring it included the main visible vessel and pulsatile blood flow. The ROI size was set