## 2 Materials and Methods
### Optical Flow Detection and Regression Modeling
#### 2.2.1 Pyramid L-K Optical Flow Feature Extraction  
The optical flow method enables the observation of pixel point motion within spatial objects depicted in an image, offering insights into the movement of bubbles within gas-liquid two-phase flow videos. Predicated on the assumption of constant brightness, the method interprets motion as \"small motion\" along the time continuum. This realization is based on the fundamental constraint equations affirming constant light intensity at characteristic pixel points before and after motion, as expressed in Equation (1) [27]. \[I(x,y,t)=I(x+dx,y+dy,t+dt) \tag{1}\]  
where \(I\) is the grayscale value of a pixel point in the image, \(x\) represents the horizontal coordinate of the pixel point in the image, \(y\) represents the vertical coordinate of the pixel point in the image, and \(t\) represents time, s.  
With \(u=\frac{dx}{dt},v=\frac{dy}{dt}\), \(I_{x}=\frac{\partial I}{\partial x},I_{y}=\frac{\partial I}{\partial y},\)_and_\(I_{t}=\frac{\partial I}{\partial t}\), the Taylor expansion of Equation (1) can be expressed in the form below:  
\[I_{x}u+I_{y}v+I_{t}=0 \tag{2}\]  
where \(u\) and \(v\) are the optical flow vectors used to calculate the motion of bubbles in the image. In this study, the pyramid Lucas-Kanade (L-K) optical flow method is selected to capture the sparse optical flow. This method has been commonly applied for analysis and recording without computing every pixel in the video, focusing solely on the bubble features within the pipeline. The pyramid optical flow method addresses the challenge of high-speed motion in video frames when the flow rate is large, while the L-K optical flow method is more suitable for fitting the optical flow at lower speeds [28; 29]. The corner function, which is used to identify the feature points or corners within an image, is crucial for computing the sparse optical flow. These feature points are typically chosen at corner locations because they exhibit significant changes in pixel brightness when a small window is shifted by a distance (\(dx\), \(dy\)). This characteristic aligns well with the requirements of Lucas-Kanade optical flow calculation, particularly in scenarios involving bubble edges. Optical flow calculations entail measuring the displacement of these corner  
Figure 3: Flow measurement flowchart. points between the two consecutive frames. The corner function can be mathematically defined as follows:  
\[E(dx,dy)=\sum\
olimits_{x,y}w(x,y)[I(x+dx,y+dy)-I(x,y)]^{2} \tag{3}\]  
where \(E(dx,dy)\) represents the grayscale change in the window after movement, \(w(x,y)\) is a window weight function, and \(I(x+dx,y+dy)-I(x,y)\) calculates the grayscale change in the window after movement. In the experiment, the [PERSON] feature detection algorithm was employed to identify the corner points within the video frames of the two-phase flow. Subsequently, through robust feature tracking, the displacement of these corner points between adjacent frames was calculated using the pyramid Lucas-Kanade (L-K) optical flow method [30]. Harris corner detection incorporates the concept of Harris response \(R\), which avoids the need to solve for eigenvectors, making the computation process more efficient [31]:  
\[R=AC-B^{2}-k(A+C)^{2} \tag{4}\]  
where \(R\) is Harris response value, \(k\) is a parameter ranging from 0.04 to 0, \(A=w(x,y){I^{\prime}}^{2}(x)\), \(B=w(x,y){I^{\prime}}^{2}(y)\), and \(C=w(x,y){I^{\prime}}x{I^{\prime}}(y)\). The pyramid optical flow computation involves adjusting the size of the detected image by creating an image \"pyramid,\" with the original image serving as layer 0. The image is then reduced by a factor of 2 L to create multiple layers, where L represents the number of pyramid levels. The top layer corresponds to the image with the lowest resolution, while the bottom layer retains the original image size.