# River Surface Space-Time Image Velocimetry Based on Dual-Channel Residual Network
## 2 Materials and Methods
### Adaptive Threshold Sobel Operator  
As an important edge detection method, Sobel is a discrete first-order difference operator, which calculates the approximation of the first-order gradient magnitude value [31]. The Sobel operator primarily employs two directional templates (\(0^{\circ}\) for horizontal and \(90^{\circ}\) for vertical edges). To enhance edge detection's completeness and accuracy in STIs, we introduce additional templates at \(45^{\circ}\) and \(135^{\circ}\), as shown in Figure 7. These four templates are used to perform convolution operations with the image \(3*3\) field. The specific calculation method is as follows [32]:  
\[\left\{\begin{array}{l}|G_  
To improve computational efficiency, the sum of absolute values is used to replace the original square and square root operations. The gradient magnitude of a point \((x,y)\) in the image distribution \(f(x,y)\) is calculated by the following equation:  
\[|\
abla f(x,y)|=|G_{0}|+|G_{45}|+|G_{90}|+|G_{135}| \tag{5}\]  
After calculating the gradient magnitude by Equation (5), the traditional Sobel operator performs edge extraction by comparing the magnitude with a fixed threshold \(Th\). Specifically, a pixel is classified as an edge point if its gradient magnitude exceeds \(Th\); otherwise, it is discarded. This thresholding operation can be expressed as  
\[g(x)=\left\{\begin{array}{c}1,|\
abla f(x,y)>Th|\\ 0,|\
abla f(x,y)\leq Th|\end{array}\right. \tag{6}\]  
The selection of an appropriate threshold is crucial for optimal edge detection performance. An excessively low threshold tends to produce false edges by misidentifying noise components, while an overly high threshold may suppress legitimate weak edges, leading to fragmented edge contours. Aiming at this problem, a threshold adaptive algorithm is used to determine the threshold. The procedure of the algorithm is to set a matrix of \(3*3\) to move smoothly in an STI with the size of \(M*N\). The value of the adaptive threshold \(Th\) is determined by calculating the gray average of the pixel values in the \(3*3\) matrix in the image. The calculation equation is as follows (\(P\) is the pixel gray value in the \(3*3\) matrix slider):  
\[Th=\frac{1}{9}(P11+P12+P13+P21+P22+P23+P31+P32+P33) \tag{7}\]  
Since the pixel gray value in the matrix is constantly changing, the calculated threshold is also changing. Each threshold is compared based on the average value in the matrix and the gradient magnitude at the center of the matrix, as shown below:  
\[g(x,y)=\left\{\begin{array}{c}1,|\
abla f(x,y)|>Th\\ X,0.5\cdot Th\leq|\
abla f(x,y)|\leq Th\\ 0,|\
abla f(x,y)|<0.5\cdot Th\end{array}\right. \tag{8}\]  
If the gradient magnitude of the central pixel is less than half of the adaptive threshold, the point is judged as a non-edge point and the output 0; if the gradient magnitude value is greater than \(Th\), it is judged as an edge point and the output 1; if the gradient magnitude is between \(0.5*Th\) and \(Th\) while the previous point is an edge point, then this point is also an edge point; otherwise, it is not. The Sobel edge detection algorithm based on the adaptive threshold and the traditional Sobel algorithm are used to process the STI. The results are shown in Figure 8. The Sobel edge detection algorithm based on the adaptive threshold is clearer and complete. Edge detection enhances texture gradient representation in STIs, while preserving essential features and suppressing irrelevant noise, thereby achieving effective data compression.  
Figure 7: Direction templates of Sobel operator.