# Pipe Spatter Detection and Grinding Robot
## 3. Sputter Image Recognition  
The spatters generated by welding are shaped like droplets and are also known in the field as eye balls because they exhibit the shape of a human eye. An image recognition method based on the consideration of this geometry was applied. The image processing captures real-time stream image input with the IP camera through ethernet cables connected to the robot and integrates with user programs via the user task teaching pendant to a C#-based algorithm to store coordinate values through image processing in DB. As shown in Figure 6, the images captured by the robot's front camera undergo various steps: image acquisition, preprocessing, region-of-interest (ROI) setting, and spatter detection. The input is quantized by the image sensor and transformed into a two-dimensional pixel array and a three-channel RGB additive mixture. Color-based algorithms cannot be used because the colors inside the pipes vary depending on the pipe material. Therefore, a one-channel gray conversion is performed on the input image to improve efficiency and processing speed [16; 17; 18]. Various gray-conversion algorithms are used for this purpose. However, because the inside of the pipe is dark, when the robot approaches the pipe outlet, light-altered pixels appear in the input image in the areas corresponding to the pipe opening and the edges of the picture. Therefore, in the gray-conversion process, the following gray-level transformation function was applied to improve spatter detection and convert the image into a one-channel gray image:  
\[H(i,j)=M(i,j)+\alpha\ if\ t_{1}\ \leq M(i,j)and\ t_  
where \(M\) and \(H\) are the gray levels before and after conversion, respectively; \(t_{1}\) and \(t_{2}\) represent the start and end points of each conversion section, respectively; \(\alpha\) is the conversion constant; \(R\) and \(C\) are the sizes of the input image; and \(i\) and \(j\) are the pixel indices. Inside the pipe, pixels that are affected by robot lighting and changes in illuminance that occur near the pipe exit appear in the input images, as shown in Figure 7. To mitigate this problem, the central part of the input image corresponding to the pipe outlet and the surrounding edges, which are affected by the lighting problem, are masked. Then, the remaining region is designated as the ROI. This method is advantageous in designating the ROI because the inner diameter of the pipe is known in advance, so the detection algorithm can be performed only on the designated area. In addition, because not all the pixels are processed using this ROI-limiting technique, the processing speed is improved by at least 20%. Finally, an algorithm is utilized to detect spatters via edge detection on the binarized image [19]. Various algorithms have been used for edge detection; in this study, the [PERSON] [20], [PERSON] [21], [PERSON] [22], Laplacian [23], and Prewitt [24] models were analyzed and compared, as shown in Figure 8 and Table 2. The image quality of the results was evaluated based on the mean squared error (MSE) to select one of the compared models. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline  & **[PERSON]** & **[PERSON]** & **Scharr** & **Laplacian** & **[PERSON]** \\ \hline
**[PERSON]** & 0 & 1.25 & 2.74 & 1.54 & 0.95 \\
**[PERSON]** & 1.25 & 0 & 1.15 & 0.69 & 0.67 \\
**[PERSON]** & 2.74 & 1.15 & 0 & 2.33 & 1.75 \\
**[PERSON]** & 1.54 & 0.69 & 2.33 & 0 & 0.82 \\
**[PERSON]** & 0.95 & 0.67 & 1.75 & 0.82 & 0 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Comparison of models based on MSE. Figure 6: Flowchart of the spatter detection algorithm. Figure 7: Masked image with ROI. Various edge-detection models were tested to determine which of them provides the fastest arithmetic processing for removing noise from the input image and minimizing the candidate group to be analyzed because it is necessary to rapidly detect spatters while moving through the pipe. In the final preprocessed image, spatter detection is confirmed using the spatter-model-based image algorithm.