The calculation of threshold segmentation is simple and efficient, but the selection of threshold needs to be determined according to the specific spur gear defect image; The segmentation effect based on region growth is good, but this method increases the computational complexity and cannot obtain complete defect regions. It needs to be improved. Figure 1 shows the effect comparison of different image segmentation methods. Image segmentation is to divide the regions with special significance in the image. The divided regions are independent of each other. Each region has similarities in color, texture and other features. Image segmentation is the key step of image processing. The n data information input in advance is divided into k clusters, and the obtained clusters are highly similar to the target class in the same cluster analysis. The spur gear defect image is divided according to the similarity of clustering analysis, and the effect image is obtained through the adaptive K-means clustering algorithm, as shown in Figure 2. Due to the different k values, the segmentation effect of spur gear image in different RGB channels is different.

In order to verify the effectiveness of the improved K-means algorithm in this paper, the experimental algorithm is analyzed for the difference value of k, k=2, k=3, k=4. When the value of k increases to 4, the segmentation effect of spur gear defects starts to deteriorate. So this paper selects k=3, and the improved K-means optimization algorithm is more detailed and can protect the details of defects. At this time, the defect image segmentation effect is the best.

(c) RGB channel segmentation results when k=3 (d) RGB channel segmentation result when k=4