# An Improved SIFT Underwater Image Stitching Method
## 3 Materials and Methods
### Underwater Image Stitching
#### 3.2.2 The Proposed Improved SIFT Method
The determination of relative positions is based on the polarity of the relative position correction symbol. When \(x_{sub}\) is positive, it indicates that the image to be matched aligns to the left of the reference image, while the reference image is to the right. Conversely, when \(y_{sub}\) is positive, it indicates that the image to be matched aligns to the top, while the reference image is below. Once the positions of the two images are established, the relative positions can be utilized for image stitching. To enhance the quality of the stitched images, we employed an improved fusion algorithm in this study. This approach involves calculating the weighted sum of pixel values within the overlapping regions of two images, taking into account the distance between these regions and the two images. These weights play a critical role in seamlessly blending the overlapping areas, thus reducing the ghosting effects and visible stitch marks in the final image. The calculation formula for the weighted sum is as follows:  
\[f= \begin{cases}f_{1},&(x,y)\in f_{1}\\ c_{1}f_{1}+c_{2}f_{2},&(x,y)\in(f_{1}\cap f_{2})\\ f_{2},&(x,y)\in f_{2},\end{cases}  \tag{15}\]  
where \(f\) is the pixel value of the fused image, \((x,y)\) is the coordinate of the concatenated image, \(f_{1}\) and \(f_{2}\) denote the pixel values of the two original images, respectively, \(c_{1}\) and \(c_{2}\) are weighting factors, and we have \(c_{1}+c_{2}=1\), \(0<c_{1}<1\), \(0<c_{2}<1\). After completing the stitching process, the identification of the stitching direction involves the determination of the overlapping area between two images. The fusion algorithm is divided into horizontal and vertical fusion categories, depending on the observed horizontal and vertical stitching characteristics during the image stitching process. The dimensions of the overlapping area, specifically its width and height, are crucial in approximating the stitching direction of the image. When the width of the overlapping part exceeds the height, the two images are categorized as being horizontally stitched, and the horizontal fusion method is applied. Conversely, if the height of the overlapping part is greater than the width, the two images are considered to be vertically stitched, and the vertical fusion method is employed. This algorithm enhances the stitching accuracy by considering the direction of stitching between the images. In the horizontal fusion method, \(f_{1}(x,y)\) and \(f_{2}(x,y)\) denote the pixel values of the original image on the left and right sides of the overlapping area, respectively, while \(c_{1}\) and \(c_{2}\) are calculated as shown below:  
\[c_{1}=\frac{x_{r}-x_{l}}{x_{r}-x_{l}} \tag{16}\]  
\[c_{2}=1-c_{1}=\frac{x_{i}-x_{l}}{x_{r}-x_{l}}, \tag{17}\]  
where \(x_{i}\) indicates the horizontal coordinate of the current pixel point, \(x_{l}\) indicates the left boundary of the overlapping area, \(x_{r}\) indicates the right boundary of the overlapping area, and \(x_{r}\
eq x_{l}\). In the vertical fusion method, \(f_{1}(x,y)\) and \(f_{2}(x,y)\) denote the pixel values of the original image at the top and bottom of the overlapping area, respectively; \(c_{1}\) and \(c_{2}\) are calculated as shown below:  
\[c_{1}=\frac{y_{d}-y_{i}}{y_{d}-y_{u}} \tag{18}\]  
\[c_{2}=1-c_{1}=\frac{y_{i}-y_{u}}{y_{d}-y_{u}}, \tag{19}\]  
where \(y_{i}\) indicates the vertical coordinate of the current pixel point, \(y_{u}\) indicates the upper boundary of the overlapping area, \(y_{d}\) indicates the lower boundary of the overlapping area, and \(y_{d}\
eq y_{u}\).