# The Bearing Surface Defect Detection Method Combining Magnetic Particle Testing and Deep Learning
## 5 Data Augmentation  
Due to the limited number of defective components in real production conditions, it is challenging to provide the required amount of data for deep learning models. A small dataset may lead to overfitting issues, resulting in missed detections [22]. Therefore, it is necessary to perform data augmentation on the collected bearing images. Traditional image augmentation methods typically involve simple affine transformations of the original images, which do not fundamentally generate new images [23]. Consequently, the challenge lies in how to generate entirely new defect samples based on the existing defect images. To address these issues, this paper proposes a bearing image data augmentation method based on dynamic thresholds and generative adversarial networks (GANs) [24]. This approach leverages a small number of existing defect images for data augmentation, creating generated samples that closely resemble the original defect samples. This enhances the diversity of the original training data, addressing the problem of limited dataset size. The schematic diagram of this data augmentation method is shown in Figure 13.  
First, using the dynamic threshold algorithm and employing the mean filtering method, average local grayscale values of the original image are calculated. A threshold is defined as the number of defects in the image. The threshold is defined as the number of defects in the image. old for extracting defect grayscale values is then set. Defective regions are dynamically extracted based on the difference between the original grayscale image and the filtered image. The dynamic extraction formula is represented by Equation (6), separating the defective portions from the original image. \[\left\{ \begin{array}{l}\mathrm{g(o)}\geq\mathrm{g(t)}+\mathrm{Offset}\ ( \mathrm{if\ LightDark}=\mathrm{light})\\ \mathrm{g(o)}\leq\mathrm{g(t)}+\mathrm{Offset}\ (\mathrm{if\ LightDark}=\mathrm{dark})\\ \mathrm{g(t)}-\mathrm{Offset}\leq\mathrm{g(o)}\leq\mathrm{g(t)}+\mathrm{Offset}\ ( \mathrm{if\ LightDark}=\mathrm{equal})\\ \mathrm{g(t)}-\mathrm{Offset}>\mathrm{g(o)}\ \mathrm{U}\ \mathrm{g(t)}+\mathrm{Offset}<\mathrm{g(o)}\ ( \mathrm{if\ LightDark}=\mathrm{not\_equal})\end{array} \right. \tag{6}\]  
In the equation, \(\mathrm{g(o)}\) represents the pixel values of the defect region to be extracted, \(\mathrm{g(t)}\) represents the pixel values of the grayscale image after mean filtering, Offset is the difference threshold between the original grayscale image and the grayscale image after mean filtering, and LightDark indicates the brightness or darkness of the defect area compared to its surroundings. The generative adversarial network (GAN) is trained through the game between the generator and discriminator. This training enables the generator to produce generated samples that are extremely similar to real samples. Therefore, it is used to augment the defect samples extracted by the dynamic threshold, thereby increasing the diversity of defect samples. StyleGAN [25], based on ProGAN improvements, is a variant of generative adversarial network proposed by NVIDIA. The StyleGAN network structure consists of a generator and a discriminator. The generator network is composed of a mapping network and a generation network. The structure of StyleGAN is shown in Figure 14.  
StyleGAN mainly decouples the latent space through a mapping network to explore the relationships between highly coupled features in the data. The mapping network transforms the latent feature \(\mathrm{z}\) into an intermediate variable \(\mathrm{w}\) through eight fully connected layers, thereby converting the distribution function of \(\mathrm{z}\) into a non-uniform density distribution that better approximates the actual feature distribution. The mapping network model allows for the generated intermediate vector \(\mathrm{w}\) to deviate from the training data distribution while reducing the coupling between features, enabling control over individual features without affecting their original interwoven characteristics.