## 2 Data Pre-Processing and Dataset Creation for Aluminum
### Dataset Image Comparison  
LBP (Local Binary Pattern) was the operator used to describe the local texture features of an image with multi-resolution, rotation invariance, gray scale invariance, etc. The main mechanism is to process the surrounding pixels using a threshold and to label the pixels of an image with binary numbers. In the LBP feature, the joint distribution function \(T\) of the local neighborhood is used to represent the texture feature of the image. Assuming that the number of pixels in the local neighborhood is \(P\) (\(P>1\)), then \(T\) can be expressed as  
\[T=t(g_{c},g_{0},\dots,g_{P-1})\ P=0,\ \dots,P-1 \tag{1}\]  
where \(g_{c}\) denotes the local neighborhood center pixel grayscale value and \(g_{P}\) denotes the neighborhood pixel grayscale value. Assuming that the central pixel and the local neighborhood pixels are independent of each other, \(T\) can be expressed as  
\[ \begin{array}{c}T=t(g_{c},g_{0}-g_{c},\ \dots,g_{P-1}-g_{c})\ P=0,\ \dots,P-1\\ \approx t(g_{c})\times t(g_{0}-g_{c},\ \dots,g_{P-1}-g_{c})\end{array}  \tag{2}\]  
where \(t(g_{c})\) determines the overall brightness of the local area, which is independent of the texture; if it is ignored, \(T\) can be obtained as  
\[T\approx t(g_{0}-g_{c},\ \dots,g_{P-1}-g_{c})\ P=0,\ \dots,P-1 \tag{3}\]  
The final result is obtained as  
\[T\approx t(s(g_{0}-g_{c}),\ \dots,s(g_{P-1}-g_{c}))\ P=0,\ \dots P-1 \tag{4}\]  
where \(s(x)= \begin{cases}1,x\geq 0\\ 0,x<0\end{cases} \), i.e., the defined \(LBP_{P,R}\), is calculated as  
\[LBP_{P,R}=\sum_{P=0}^{P-1}\!\!\!s(g_{P}-g_{c})2^{P}\ P=0,\ \dots P-1 \tag{5}\]  
In Figure 7, a window of 3 \(\times\) 3 size is used as an example, and the center pixel is taken as the threshold value and compared with the eight pixels in the neighborhood. If the center pixel is larger than the neighboring pixels, the pixel is assigned a value of 1; otherwise, it is 0, and an 8-bit binary number is generated, after which the binary numbers are arranged in the clockwise direction and the LBP value of the center pixel is calculated to be 19. Feature extraction was performed on the collected aluminum blocks of different grades. Firstly, the BGR image was converted into an RGB image (src), which was in turn converted into a grayscale image (gray); the grayscale histogram was drawn, as were the histograms of the R, G, and B channels, and the LBP texture features were extracted from these. Figure 8 shows the process of converting the input image (src) into RGB and grayscale, and then extracting LBP texture features. It can be seen that in the input images of the different grades, there were also obvious differences in the RGB images; there was a greater  
Figure 7: Principle of LBP feature extraction. is larger than that of grades 5052 and 6061, and the extreme value of 12,000 can be used as the dividing line. At 190 brightness, the extreme value of 6061 is greater than 1000, much larger than those of 1060 and 5052, and this can be used as the dividing line between 5052 and 6061. It can be seen that the classification of the three grades can be realized through the grayscale images. The histograms of the R, G, and B channels of the RGB images are shown in Figure 10.  
Specifically analyzing the differences between the R, B, and G color channels, the histograms show that in the R channel, the extreme values of 1060 and 6061 are both greater than 20,000, significantly higher than that of 5052, with 1060 slightly higher than 6061; in the B channel, the extreme values of 5052 and 6061 were both greater than 20,000, much greater than that of 1060, and the slopes of 5052 and 6061 were steeper while that of 1060 was relatively gentle; in the G channel, the extreme value of 1060 was larger than those of 5052 and 6061, and the extreme brightness of 1060 was near 75, while the extreme brightnesses of 5052 and 6061 were in the ranges of 110-114 and 124-126, respectively, with a clear demarcation line.