Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 7, No. 2, 2023 227 Metal Abrasive Image Segmentation Algorithm Based on K‐means Clustering Pengpeng Zhang, Wei Wu, Yu Li, Yukun Wang School of Mechanical Engineering, Xi'an Shiyou University, Xi'an 710000, China Abstract: Metal abrasive image segmentation is one of the important image processing tasks in the industrial field. However, due to the complex color and texture characteristics of metal abrasive images, as well as difficult factors such as noise and lighting changes, traditional image segmentation methods often fail to achieve high accuracy and stability. In order to solve this problem, a metal abrasive image segmentation algorithm based on K-means clustering is proposed. The algorithm applies the K- means clustering algorithm to the image segmentation of metal abrasive particles, and realizes the separation of metal abrasive grains from the background by clustering the color features of image pixels. Experimental results show that our algorithm shows good accuracy and stability in the metal abrasive image segmentation task, and has high efficiency. Therefore, the algorithm provides an accurate and efficient method for metal abrasive image segmentation. Keywords: Metal abrasive images; Image segmentation; K-means clustering. 1. Introduction Metal abrasive image segmentation is one of the most important image processing tasks in the industrial field. In applications such as metalworking, surface inspection, and quality control, accurately segmenting metal abrasives from other backgrounds is an essential step. However, due to the complex color and texture characteristics of metal abrasive images, as well as the existence of difficult factors such as noise and light changes, traditional image segmentation methods often fail to achieve high accuracy and stability. This paper aims to propose a metal abrasive image segmentation algorithm based on K-means clustering to solve the limitations and challenges of traditional methods in metal abrasive image segmentation. Specifically, our research goal is to design an efficient and accurate algorithm that can automatically and efficiently separate metal abrasives from the background and overcome problems such as noise, light variation, and color differences. Through the research in this paper, we hope to provide an accurate and efficient method for metal abrasive image segmentation, and promote the development and application in the field of metal processing and quality control. 2. Related Research 2.1. Application of K-means clustering algorithm in image segmentation Image clustering is a classification problem based on color and feature space, and commonly used methods include K- means clustering algorithm (K-means) and fuzzy C-means clustering (FCM) algorithm. Its Chinese [1][4]is processed using the fuzzy C-means clustering algorithm. The fuzzy C- means clustering algorithm can handle the initial parameters and noise and grayscale unevenness well, but does not pay attention to the spatial information in the image [5] Researchers have also adopted a variety of methods to study the K-means clustering algorithm, among which Qiu Lijuan et al. [6]proposed to select color images of various morphologies and colors. On the basis of color characteristics, cluster analysis and maximum interclass variance threshold segmentation are carried out, and a single complete abrasive grain is obtained after image segmentation, but the abrasive grain will fuse with the background in the area with weak light or low relative brightness of the abrasive grain, which will lose part of the abrasive grain information, resulting in incomplete particle extraction, and eventually incomplete segmentation 2.2. Review of K-means algorithm image segmentation algorithm The K-means algorithm first selects K points from the data sample as the initial clustering center. Secondly, the distance from each sample to the cluster is calculated, and the sample is classified into the class where the cluster center closest to it is located; Then calculate the average of the data objects of each newly formed cluster to obtain the new cluster center; Finally, repeat the above steps until there is no change in the cluster center of the adjacent two times, indicating that the sample adjustment is over and the clustering criterion function reaches the optimal [[7][12] The specific description is as follows: (1) Take any K attribute value vector as the initial center, and let this value be , π‘Œ 𝑙 ,π‘Œ 𝑙 ....,, the π‘Œ 𝑙 number of loop processing is set to n, and its initial value is set to 1. (2) All attribute value vectors X are classified by the following equation so that the vectors in the vector set {X} belong to the center of the cluster, π‘Œ 𝑛 ,...,, , π‘Œ 𝑛 the corresponding subset, π‘Œ 𝑛 π‘Œ 𝑛 𝑆 𝑛 , 𝑆 𝑛 , .... , 𝑆 𝑛 ,𝑆 𝑛 。 𝑑 π‘šπ‘–π‘› 𝑑 β†’ π‘‹πœ–π‘† 𝑛 ,𝑁 β‰œ 1,2, 𝐾 (3) This refers to the distance between X and , defined by the following equation.𝑑 π‘Œ 𝑛 𝑑 β‰œ 𝑋 π‘Œ 𝑛 (4) The center of the new cluster of each subset (𝑆 𝑛 l) is calculated by the following equationβ‰… 1,2,3, … , K . π‘Œ 𝑛 1 π‘Œ 𝑛 1 1 𝑁 𝑋 ∈ 228 𝑁 - The number of elements in the set𝑆 𝑛 π‘Œ 𝑛 1 - the average of the X that belongs𝑆 𝑛 (5) For all clusters, processing ends when the following equation holds, otherwise return to (2) to continue processing. π‘Œ 𝑛 1 π‘Œ 𝑛 The algorithm proposed in this study is based on the K- means clustering algorithm, which is a commonly used unsupervised learning method that can cluster image pixels into different categories according to similarity. We apply the K-means algorithm to the image segmentation of metal abrasive grains, and realize the separation of metal abrasive grains from the background by clustering the color features of image pixels. Flow chart of K-means clustering algorithm [13] 3. The Details and Process of Metal Abrasive Image Segmentation Algorithm Based on K-means 1. Data pre-processing: Read the metal abrasive image and convert it to grayscale image or color space conversion for subsequent processing. The image is denoised and enhanced using an adaptive filtering algorithm. 2. Feature extraction: Extract features for clustering from preprocessed images. Common features include color features, texture features, and shape features are normalized to ensure consistent dimensions between different features. 3. K-means clustering: Initialize K cluster centers, which can be selected randomly or determined empirically. The features of the image are clustered, and each pixel is assigned to the nearest cluster center to form K categories. Update the cluster center, calculating the center point of each category as the new cluster center. Repeat Steps b and c until convergence conditions are reached (e.g., cluster centers no longer change significantly). 4. Segmentation result generation: According to the clustering results, the pixels in the image are classified as metal abrasive grains or backgrounds, and simple threshold determination or other classification rules can be used. Based on the segmentation results, binary images are generated, marking metal abrasives and backgrounds. 5. Post-processing: Post-processing of image processing technology on segmentation results, such as filling voids, removing small noise, etc., to improve the quality of segmentation results. Optionally, image restoration, edge enhancement or other image enhancement processing can be performed according to the actual application needs. The algorithm realizes the separation of metal abrasive grains from the background by using the K-means clustering algorithm to cluster the pixels in the metal abrasive image. By clustering the color features of the image, the algorithm is able to more accurately segment the metal abrasive grain from 229 the background. At the same time, with appropriate data pre- and post-processing steps, the algorithm can also improve the quality of segmentation results. Experimental results show that the metal abrasive image segmentation algorithm based on K-means has high accuracy, stability and efficiency in the metal abrasive image segmentation task, and can be applied to metal processing, surface detection and quality control. 4. Experimental Settings and Index Selection 4.1. Experimental setup: 1. Image selection: Select a metal abrasive image as the input data for the experiment. Ensure that the selected images contain metal abrasives with different size, shape, and color characteristics to fully examine the adaptability and robustness of the algorithm. 2. Data preprocessing: Preprocessing operations such as grayscale, size normalization, etc. are performed on the selected images for application to K-means clustering algorithms. 3. Feature extraction: Extract relevant feature vectors from images. In this paper, a feature vector from the Lab's color space is chosen as input for K-means clustering. The extraction of feature vectors can be done by transforming the image into Lab space and then taking the Lab-value of each pixel as part of the feature vector. 4. Set the number of clusters: In order to study the metal abrasive image segmentation algorithm based on K-means clustering, it is necessary to set different cluster numbers, and this paper studies 2, 3, 4, 5, and 6 to compare the segmentation effect under different cluster numbers. 5. . Analysis of Experimental Results 5.1. Display of experimental results Figure 1. Original image Figure 2. Number of clusters = 2 Figure 3. Number of clusters = 3 Figure 4. Number of clusters = 4 Figure 5. Number of clusters = 5 Figure 6. Number of clusters = 6 The effect of K-means clustering segmentation of abrasive images is shown in Figure 1~6. When using 3 clusters, the abrasive grain can be significantly separated from the background: when using 5~6 clusters, the abrasive, background, and noise can be well distinguished. 230 5.2. Algorithm superiority The metal abrasive image segmentation algorithm based on K-means clustering has the following advantages compared with other algorithms: 1. Simple and efficient: K-means clustering algorithm is a simple and efficient clustering algorithm, which is suitable for metal abrasive image segmentation tasks. Its principle is simple, the calculation speed is fast, and it can quickly process large-scale image data [14] 2. No prior knowledge required: The K-means clustering algorithm is an unsupervised learning method that does not require prior knowledge or labeled data. It can automatically learn the clustering pattern of metal abrasives from the input image without the need to label the metal abrasives in advance or manually provide any prior information [15] 3. High clustering accuracy: The K-means clustering algorithm can effectively divide the pixels in the image into different clustering clusters in the metal abrasive image segmentation task. It excels in clustering accuracy, accurately grouping the same type of metal abrasive pixels into a class, achieving better segmentation [16] 4. Strong robustness: The K-means clustering algorithm has good robustness for noise and image changes. In the metal abrasive image, there may be noise or some metal abrasive grains that vary greatly in shape and color. The K-means algorithm can identify and separate these metal abrasive particles with large changes by minimizing the distance between data points and minimizing the variance within the cluster, which improves the robustness of the algorithm. 5. Strong interpretability: The cluster centers generated by the K-means clustering algorithm represent different metal abrasive grain types. These clustering centers can be interpreted as metal abrasive grains with similar shape and color characteristics. Therefore, the K-means algorithm can not only provide accurate segmentation results, but also provide the characteristic understanding and interpretation of metal abrasive [17] 6. . Conclusion In this paper, a metal abrasive image segmentation algorithm based on K-means clustering algorithm is proposed and compared with other algorithms. Through experimental verification, the proposed algorithm has advantages in accuracy, efficiency, unsupervised learning, robustness and interpretability. Although the metal abrasive image segmentation algorithm based on K-means clustering proposed in this paper has achieved good results in the metal abrasive image segmentation task, there are still some directions that can be improved and further studied: 1. Algorithm optimization: further optimize the parameter selection and cluster center initialization method of K-means clustering algorithm. At the same time, combined with other clustering algorithms or feature extraction methods, the accuracy and robustness of the algorithm are further improved. 2. Multi-scale segmentation: Considering the problem of multiple scales and resolutions in metal abrasive images, you can try to design a multi-scale segmentation algorithm to process metal abrasive grains of different scales. 3. Dataset expansion: The algorithm in this study is mainly based on the specific metal abrasive grain dataset, which can further expand and enrich the dataset, especially the metal abrasive grain samples containing more shape and color changes, so as to increase the generalization ability of the algorithm. 4. Deep learning methods: You can try to apply deep learning methods, such as convolutional neural networks (CNNs), to process the segmentation task of metal abrasive images, so as to further improve the segmentation accuracy and the ability to process complex scenes. 5. Application expansion: In addition to metal abrasive image segmentation, the algorithm proposed in this paper can also be applied and extended in other image segmentation tasks, such as medical image segmentation and natural image segmentation. Through further research and improvement, the effect of the metal abrasive image segmentation algorithm can be improved, its application field can be expanded, and better solutions can be provided for practical applications. References [1] CHEN G, ZUO H F.Object extraction of color microscope debris images based on fuzzy cluster analysis [J].Journal of Data Acquisition οΌ† Processing, 2001, 16( 3) : 286-290. [2] XU Y F.Image segmentation based on the genetic fuzzy C- mean algorithm [J].Journal of Northwestern Polytechnical University, 2002, 20( 4) : 549-553. [3] LI Y J, ZUO H F, CHEN G, et al.Genetic FCM algorithm for wear particle image objective extracting [J].Pattern οΌ² ecognition and Artificial Intelligence, 2003, 16( 3) : 379-383. [4] GUO H G, QU J, WANG X H. Wear particle color image segmentation based on color feature and texture feature [J].Lubrication Engineering, 2013, 38( 6) : 94-97. [5] ZHANG L.Application research of ant colony algorithm in ferrography image processing [D].Nanjing: Nanjing University of Aeronautics and Astronautics, 2013. [6] QIU L J, XUAN Z N, ZHANG X F.Debris color image segmentaion by K - means clustering and ostu method [J].Lubrication Engineering, 2014, 39( 12) : 101-104. [7] Maiti Abhik,Choudhary Amrit,Chakravarty Debashish. A k- means clustering–based approach for 3D mapping and characterization of rock faces using digital images[J]. Arabian Journal of Geosciences,2021,14(10). [8] Wang Xinsai,Feng Weiqiang,Feng Xiaoer. Research on image fusion algorithm based on K-means clustering and NSCT[J]. SEVENTH SYMPOSIUM ON NOVEL PHOTOELECTRONIC DETECTION TECHNOLOGY AND APPLICATIONS,2021,11763. [9] Yuchechen AdriΓ‘n E., Lakkis S. Gabriela, Caferri AgustΓ­n, Canziani Pablo O., Muszkats Juan Pablo. A Cluster Approach to Cloud Cover Classification over South America and Adjacent Oceans Using a k-means/k-means++ Unsupervised Algorithm on GOES IR Imagery[J]. Remote Sensing, 2020, 12(18). [10] Sensor Research; Studies from Beijing University of Chemical Technology in the Area of Sensor Research Described (Research on Tire Marking Point Completeness Evaluation Based on K-Means Clustering Image Segmentation)[J]. Journal of Technology,2020. [11] Multi-Spectral Image Segmentation Based on the K-means Clustering[J]. International Journal of Innovative Technology and Exploring Engineering,2019,9(2). [12] Yanhong Wang,Denghui Li,Yuying Wang. Realization of remote sensing image segmentation based on K-means clustering[J]. IOP Conference Series: Materials Science and Engineering,2019,490(7). 231 [13] Angky Fajriati MS Musa,Adiwijaya,Dody Qori Utama. Segmentation image re-coloring based on k-means clustering algorithm as a tool for partial color-blind people[J]. Journal of Physics: Conference Series,2019,1192(1). [14] Juli Rejito,Atje Setiawan Abdullahi,Akmal,Deni Setiana,Budi Nurani Ruchjana. Image indexing using color histogram and k- means clustering for optimization CBIR in image database[J]. Journal of Physics: Conference Series,2017,893(1). [15] Senthan Mathavan,Akash Kumar,Khurram Kamal,Michael Nieminen,Hitesh Shah,Mujib Rahman. Fast segmentation of industrial quality pavement images using Laws texture energy measures and k -means clustering[J]. Journal of Electronic Imaging,2016,25(5). [16] Somasundaram K.,Mary Shanthi Rani M.. Eigen Value based K-means Clustering for Image Compression[J]. International Journal of Applied Information Systems,2012,3(7). [17] Guo Yu,Weng Guirong. K-means++ clustering-based active contour model for fast image segmentation[J]. Journal of Electronic Imaging,2018,27(6).