# Detection and Classification of Bearing Surface Defects Based on Machine Vision
## 3 Materials and Methods
### Precision Segmentation of Defect Region  
Gaussian filter processing is used in the defect detection process. The process eliminates noise but also blurs the boundary of the defect, reduces the accuracy of the segmentation of the defect region, and can even affect the classification of the defect. Therefore, it is necessary to perform accurate segmentation of the region obtained above.  
To address this situation based on previous research, we proposed a local multiple neural network (Lc-MNN) image segmentation algorithm for extracting the features with the wavelet transform to further process the initial segmented images to improve the accuracy of segmentation. The application of the algorithm was carried out based on the initially segmented results. The algorithm comprises three steps: feature extraction with the wavelet transform, region division with Lc-MNN, and classification and post-processing with Lc-MNN. The steps are as follows.  
1. Wavelet transform feature extraction: perform a three-layer wavelet transform on the original image to obtain a series of high-frequency and low-frequency images stacked in a pyramid structure (as shown in Figure 5a). These images are expanded to the size of the original image by nearest-neighbor interpolation (as shown in Figure 5b), together with the original image. Each pixel location is characterized by an 11-dimensional feature to form a feature vector for each pixel.
2. Lc-MNN region division: first, perform morphological processing of the image using the boundary of the initial segmentation to form an overall to-be-classified region, a target sample region, and a background sample region centered on the boundary. Then, fit the boundary curve with an N-sided polygon and generate N symmetric rectangles centered on the N sides, with each rectangle representing a neural-network region. Finally, each rectangle is intersected with the overall to-be-classified region, the target sample region, and the background sample region to obtain the to-be-classified region, the target sample region, and the background sample region of each neural-network region.  
Figure 4: Test results obtained using image detection algorithm for different defects: (**a**) original image of over-grinding; (**b**) detection result of over-grinding; (**c**) original image of the scratch defect; (**d**) detection results of the scratch defect; (**e**) original image of the bruise defect; (**f**) detection results of the bruise defect.  
* Lc-MNN classification and post-processing. After the above two steps, the training sample and to-be-classified pixel in the i-th neural network region can be represented by 11-dimensional features. Use training samples to train the neural network to obtain the neural network classifier, and then the feature vector of the pixel to be classified is input into the classifier to obtain the classification result of whether each pixel belongs to the target region. This process may produce unconnected areas or holes in the area, but these artifacts may be eliminated through regional operations to obtain the segmentation results.  
The framework of the algorithm is shown in Figure 6.