# Automatic Segmentation of Gas Metal Arc Welding for Cleaner Productions
## 3 Materials and Methods
### Automatic Segmentation Methodology  
The automated inspection of weld beads in the metallurgical industry, particularly in GMAW processes, plays a fundamental role in ensuring the quality and structural integrity of the welded components. Defect identification in welded joints remains a critical challenge, as undetected flaws can compromise mechanical performance and lead to premature failure of industrial structures [6; 37; 38].  
Traditional inspection methods rely on visual examination by certified welders, an inherently time-consuming process susceptible to human error. To overcome these limitations, it is necessary to implement advanced image segmentation techniques to identify regions of interest accurately without manual intervention.  
The research methodology of this paper includes the welding, the image acquisition, and the segmentation of the region of interest (Figure 7).  
This study acquired a dataset of 30 weld bead images under controlled conditions to facilitate a comprehensive analysis of segmentation performance. These images encompass a range of weld bead characteristics, including geometric irregularities, porosity, and structural deviations (Figure 8), providing a representative sample for evaluating segmentation accuracy and reliability.  
A human expert manually delineated the ROI within the automotive component to evaluate the performance of various segmentation algorithms. This expert segmentation served as the ground truth for comparative analysis, enabling an objective assessment of each algorithm's ability to identify the region of interest accurately.  
Original images were acquired in RGB format and converted to grayscale to standardize preprocessing and enhance contrast for segmentation. Multiple segmentation techniques were then applied to determine their effectiveness in isolating ROI. The algorithms implemented included binary segmentation, binary segmentation combined with OTSU thresholding method, standalone OTSU thresholding, and binary segmentation combined with triangular thresholding.  
Once the binary masks were generated, the Contours method was employed to identify and extract the most prominent contours within the segmented images. A blank matrix matching the original image's dimensions was created to facilitate further analysis, onto which the largest detected contours were mapped.  
Figure 6: Equipment of Automotive Cell Laboratory by ESIME Azcapotzalco Unit–IPN. Examples (**a**) First view; (**b**) Second view.  
Additionally, Rembg library (a background removal tool based on neural networks [9]) was utilized as an alternative segmentation approach. The key steps of this segmentation methodology are illustrated in Figure 9.  
Figure 8: Image of welding seams in the automotive parts. The image presents the photograph captured in the central position. This image will be further used as a reference throughout the paper.  
Figure 7: Research methodology.  
To apply the Rembg method, the input images must be in.jpeg format. This technique utilizes a pre-trained deep learning model (U2 Net) to generate an initial segmentation mask. The resulting mask undergoes a post-processing stage to refine its quality by eliminating artifacts and enhancing contour definition. This refinement is achieved through morphological operations, which reduce noise, improve the structural integrity of the segmented region, and smooth the mask edges.  
The background removal process involves cropping the image and combining the original input with its corresponding binary mask, ensuring that only the region of interest remains. Finally, the processed images are preserved in the same format as the input data, maintaining consistency for further analysis.