## 3 Image Processing of Weld Seams
### Laser Stripe Center Extraction Algorithm  
Image preprocessing effectively eliminates most noise in weld seam images. However, the line laser projected by the sensor has a certain width, causing the noise-free laser stripe to span 3-12 pixels in the image's column direction. Therefore, extracting the weld seam feature information requires laser stripe center extraction after image preprocessing. Common algorithms for this task include the extremum method, the grayscale centroid method, and curve fitting methods [31]. In practical welding environments, the algorithm must ensure high accuracy and fast computation speed. Consequently, algorithms that only traverse the image in the column direction, such as the gray extreme value and gray centroid methods, are frequently used due to their rapid processing speed. However, these methods have inherent limitations. The extremum method can accurately locate the laser stripe region without interference from isolated noise but is vulnerable to bright reflective noise near the stripe. Conversely, the grayscale centroid method is less affected by single abnormally bright pixels and provides smoother extraction results across columns, yet it is more prone to extraction deviations caused by isolated noise. To overcome these limitations, this paper combines the strengths of both methods. The extremum method first locates the laser stripe region, and then the grayscale centroid method is applied within this region to extract the laser stripe center. The steps of the improved grayscale extremum centroid method are as follows:  
Step 1: Traverse all pixels in the j-th column of the weld seam image to determine the maximum grayscale value \(g_{\text{max}}\) and its corresponding row number \(h_{\text{max}}\). Step 2: If \(g_{\text{max}}\) in this column is less than the threshold \(g_{\text{b}}\) used to differentiate the background, skip this column and return to Step 1 to traverse the j + 1-th column. Step 3: If \(g_{\text{max}}>g_{\text{b}}\), record the grayscale values of \(k_{\text{cen}}\) rows above and below \(h_{\text{max}}\) (where \(k_{\text{cen}}\) is an empirical value; in this study, \(k_{\text{cen}}=\)8 based on the sensor's actual working conditions). This gives a total of \(2k_{\text{cen}}+1\) sampling points. Step 4: Use the grayscale centroid method to calculate the centroid of these \(2k_{\text{cen}}+1\) sampling points, determining the center \(cent_{j}\) of the laser stripe in the j-th column, using the following formula:  
\[cent_{j}=\frac{\sum_{i=h_{\text{max}}-k_{\text{cen}}}^{h_{\text{max}}+k_{\text{ cen}}}g(i,j)\times i}{\sum_{i=h_{\text{max}}-k_{\text{cen}}}^{h_{\text{max}}+k_{ \text{cen}}}g(i,j)} \tag{15}\]  
Step 5: Repeat Step 1 for the j + 1-th column, continuing this process until the laser stripe for the entire weld seam image is fully extracted. To assess the effectiveness of the proposed algorithm, the laser stripe center was extracted from weld seam images using the gray extreme value method, the grayscale  
Figure 5: Comparison of weld seam images before and after preprocessing: (**a**) weld seam image before preprocessing; (**b**) weld seam image after preprocessing. The noise is indicated by red dashed rectangles. centroid method, and the improved grayscale extremum centroid method, as shown in Figure 6. In comparison to Figure 6a,b, the improved gray extreme centroid method is unaffected by reflective noise at the weld seam corners and isolated noise, offering a smoother transition of center points along the same straight line. The results demonstrate that the improved grayscale extremum centroid method provides higher accuracy and better adaptability to varying conditions. Given that the true position of the laser center point is unknown, this paper follows the method outlined in reference [32], utilizing the root mean square error (RMSE) of the distance between the extracted laser stripe center points and the fitted line to evaluate the algorithm's accuracy in center point extraction.