## 2 Materials and Methods
### Image Preprocessing and Data Augmentation  
After completing the experiment, a dataset with 4752 elements was obtained. Three preprocessing image variations were employed to evaluate the model performance and understand the network behavior. The first dataset was processed using a simple cutting algorithm to resize the MONDI dataset to 676 \(\times\) 676 pixels. This process was performed to remove unnecessary parts, thereby increasing the training efficiency.  
The second dataset was processed by using the contrast-limited adaptive histogram equalization (CLAHE) algorithm to improve image clarity, which helps in feature extraction in the CNN algorithm. CLAHE is a contrast-limit equalization process; it uses an enhancement function applied to all neighborhood pixels. The process is then completed by deriving a transformation function [32; 33]. The CLAHE algorithm utilizes histogram equalization to measure the intensity level of the MONDI image, thereby enhancing the image quality by increasing the contrast level to address excessive shadows and provide better defect details. Equation (4) shows the gray-level mapping and clipped histogram using the average number of pixels (\(N_{avg}\)), where \(N_{CR-xp}\) and \(N_{CR-yp}\) are the number of pixels in the X and Y directions, respectively, and \(N_{gray}\) is the number of gray levels. CLAHE also has distinct advantages as a noise image limiter, i.e., by, using the cliplimit function to increase the image clarity and accuracy of the image extraction process. Equation (5) shows the function for calculating the actual number of cliplimit pixels (\(N_{CL}\)), where \(N_{CLIP}\) is the actual current pixel in the target image.  
\[N_{avg}=\frac{N_{CR-xp}\cdot N_{CR-yp}}{N_{gray}} \tag{4}\]  
\[N_{CL}=N_{CLIP}\cdot\ N_{avg} \tag{5}\]  
The third dataset was processed by using a histogram brightness transformation (HBT) to extract the defect images. The HBT method works in a manner similar to that of a filter, by transforming matrix values unsuitable for the filter threshold. However, directly extracting the raw data causes a defect to lose some critical parts, especially on the edges. Degradation occurs during extraction because the raw image contains a foggy edge that confuses the extraction algorithm. The CLAHE dataset was used in this extraction dataset to address these challenges. The filter threshold was set to one-third of the maximum and minimum image intensities. The algorithm transformed each image pixel with a brightness between the threshold to 0 (black) and those with brightness suitable on the threshold to 255 (white). This method efficiently extracted the defect shapes. The MONDI system depends on the reflection intensity; thus, using the image pixel intensity as the threshold promises high accuracy and reduces biased results. Figure 5 shows a histogram analysis of each preprocessing step.  
Figure 5: Image histogram analysis: (**a**) raw image, (**b**) contrast-limited adaptive histogram equalization (CLAHE) image, and (**c**) extraction image.  
After completing the preprocessing and defect extraction, the three variation datasets were trained using a transfer learning method. However, directly processing this dataset increased the potential for overfitting the training. Overfitting can be a severe problem in a prediction model, especially if there is a weak relationship between the research outcome and predictor set variable [34]. Accordingly, an image augmentation layer was applied to generate random transformations in the datasets to prevent this condition. The augmented layer performed a random translation from \(-3\%\) to \(3\%\) of the image size in the x- and y-directions. This process increased the relationship among the features and reduced the possibility of overfitting training (Figure 2).