Frontiers in Computing and Intelligent Systems ISSN: 2832-6024 | Vol. 10, No. 1, 2024 97 Research on Particle Swarm Image Threshold Segmentation Method Based on Rough Set Dongpo Zhang, Zhiyong She and Jiaqi Zhang School of Information Network Security, Xinjiang University of Political Science and Law, Tumshuk Xinjiang, 844000, China Abstract: Image processing is an important way to obtain information and is widely used in important fields such as military, medical and transportation. Image segmentation plays an important role in image processing. In view of the inherent complexity and correlation of the image itself, how to deal with the uncertainty in the image segmentation process is the main work to obtain a more accurate image segmentation result. We propose an image single-threshold segmentation algorithm using the maximum dependency of variable precision rough set (VPRS). The algorithm uses VPRS to represent the image, and uses the maximum dependency and particle swarm optimization to solve the optimal image segmentation threshold, which effectively handles the uncertainty in image segmentation. The experiments show that the single-threshold segmentation algorithm has certain practicability and flexibility, the segmentation effect is better than the maximum average information entropy method, and the segmentation efficiency is significantly higher than the ordinary iterative method. Keywords: Variable Precision Rough Set; Dependency; Particle Swarm Optimization; Image Single-threshold Segmentation. 1. Introduction Image segmentation is a classic worldwide problem. Currently, there is no universal segmentation algorithm. The inherent complexity and blur of the image itself make image segmentation difficult, so the main task of image segmentation is to deal with the uncertainty in the segmentation process. Threshold segmentation is a commonly used segmentation algorithm, which is simple, intuitive, and easy to implement. It is also one of the hot topics in current research. Traditional threshold segmentation mainly includes manual selection threshold method and automatic selection threshold method. The manual selection threshold method has a certain subjective blindness in solving the optimal segmentation threshold. The automatic selection threshold method generally includes iterative method, maximum between-class variance method and maximum average information entropy method. The three methods objectively solve the optimal segmentation threshold through the adaptation function, and they cannot effectively deal with the uncertainties in image segmentation. Zhu Liangkuan et al. [1] proposed forest canopy image segmentation based on an improved 3-D Otsu method. The core of the algorithm is to use the knowledge of posterior probability to process the uncertainty in the image. Lei Xiangxiao et al. [2] proposed the image segmentation based on equivalent 3-D entropy and whale optimization algorithm. The entropy theory is used to measure the uncertain factors in the image. Finally, the whale optimization algorithm is used to improve the efficiency of the algorithm. Nabanita Mahata et al. [3] segmented 3-D brain magnetic resonance images by minimizing global and local entropy space constraints, and also used entropy to process image uncertainty. Xiaofeng Yue et al. [4] used the hybrid bat algorithm to segment the image. The algorithm combines genetic crossover operations and smart inertia weight, and uses the between-class variance and Kapur entropy as the objective function to solve the optimal segmentation threshold. The common point of the segmentation algorithms proposed by the above scholars is to use posterior probability to solve the uncertainties in image segmentation. But in practice, the posterior probability cannot effectively deal with the uncertainty in image segmentation. In this paper, we propose an effective single-threshold segmentation algorithm. The image is processed with variable precision rough set (VPRS), the maximum segmentation threshold is used to solve the optimal segmentation threshold, and the particle swarm optimization is used to improve the efficiency of the algorithm. Rough set is an effective mathematical tool for dealing with uncertainty and ambiguity [5,6]. The greater the dependency in VPRS, the closer the relationship between attributes. We will construct a new dependency function. When the dependency value is maximized, the corresponding segmentation threshold is used as the best image segmentation threshold. Experiments compare the proposed algorithm with current commonly used algorithms and iterative methods to verify the advantages of the algorithm in this paper [7]. 2. Basic Theory 2.1. Variable Precision Rough Set Definition 1. Knowledge base S can be effectively represented as a quaternion ( , , , )S U R V f . The finite set U  , called domain. The set R is a non-empty finite set of attributes, 1 2{ , , , }mR R R R  . The set iV V  is a range of attributes iR . The function expression :f U R V  can be understood as: r R  , x U , ( , ) rf x a V . In order to solve the defects of Pawlak rough set, Ziarko proposed a variable precision rough set (VPRS) model. VPRS introduces a variable, the classification error  ( 0 0.5  ). With the existence of this variable, VPRS is more widely used. In fact, when 0  , VPRS is a special case of Pawlak rough set. This conclusion will be explained below. Definition 2. Let set X U and X  , where U is a finite set. If e X  and e Y  , then Y X . Let 98 1 | | / | |,| | 0 ( , ) 0 ,| | 0 X Y X X c X Y X      (1) then ( , )c X Y is called the misclassification rate of the set X with respect to set Y . Definition 3. Let 0 0.5  , then the majority inclusion relation is defined as: ( , )Y X c X Y     . Definition 4. Let ( , )U R be a knowledge base, where U , R be the upper equivalence relation of U , and 1 2/ { , , , }nU R E E E  be the basic equivalence classification of R . For the set X U : The  -lower approximation set of X : { / | }R X E U R X E      or { / | ( , ) }R X E U R c E X    , where R X is also referred to as  -positive region, denoted as ( )POSR X . The  -upper approximation set of X : { / | ( , ) 1 }R X E U R c E X     . The  -boundary region of X : ( ) { / | ( , ) 1 }BNR X E U R c E X       . The  -negative region of X : ( ) { / | ( , ) 1 }NEGR X E U R c E X     . The  -accuracy of X : ( ) ( , , ) ( ) card R X R X card R X      (2) The  -roughness of X : ( , , ) 1 ( , , )R X R X     . It can be seen from definition 4 that when =0 , VPRS will evolve into Pawlak rough set, and theorem 1 can be obtained through the definition. Theorem 1. R X RX  , RX R X , RBN X BNR X , RNEGR X NEG X  . From Theorem 1, it can be seen that the quantitative relationships between  and  of the Pawlak rough set model and the VPRS model are: ( ) ( , , )R X R X   , ( , , ) ( )RR X X   (3) From Definition 4 and Theorem 1, we know that the classification error  is the core of the upper and lower approximation sets that define VPRS. When  changes a certain number of relationships, the change relationship of each amount of VPRS is shown in Table 1. Table 1. Variations in VPRS caused by changes in   (Classification error) R X (Lower appro- ximation set) R X (Upper appro- ximation set) ( , , )R X  (Accuracy) ( , , )R X  (Roughness) BNR X (boundary region) Decrease Decrease Increase Decrease Increase Increase Increase Increase Decrease Increase Decrease Decrease As can be seen from Table 1,  roughness is used to describe the inaccuracy of the set X . As  increases, R X increases, R X decreases, and BNR X decreases. The inaccuracy of rough sets is caused by the presence of BNR X . The smaller BNR X is, the more accurate the objects described by the rough set are. According to Theorem 1, the boundary region of the Pawlak rough set model is larger than the boundary region of the VPRS model, which indicates that VPRS can accurately describe the object. Let ( , ) {0 0.5 | ( ) }ndis R X BNR X     , then the minimum upper bound of ( , )ndis R X is ( , ) sup ( , )R X ndis R X  . Theorem 2. 1 2( , ) max( , )R X m m  , where 1 1 min{ ( , ) | / , 0.5 ( , )}m c E X E U R c E X    , 2 max{ ( , ) | / , ( , ) 0.5}m c E X E U R c E X   . Definition 5. Let ( , , , )S U R V f be an information system. P and Q are condition attribute set and decision attribute set, respectively, and ,P Q R . ( ), ( )IND P IND Q represents two equivalent classifications determined by ,P Q . The equivalent classification set of the attribute P is called a condition class, and it is represented by /U P . The equivalent classification set of the attribute Q is called a decision class, and it is represented by /U Q . The  dependency of Q and P is: ( , , ) ( ( , , )) ( )P Q card POS P Q card U   (4) where /( , , ) ( )Y U QPOS P Q IND P Y     . 2.2. Particle Swarm Optimization The idea of particle swarm optimization (PSO) comes from the research of bird foraging behavior. Their way of foraging is done by cooperating with each other. Similarly, in the practical application, the algorithm obtains the individual optimal solution and local optimal solution through continuous iteration, and finally obtains the global optimal solution [8]. Suppose there is a D -dimensional target search space with a group of N particles. The i th particle is represented as a n -dimensional vector 1 2{ , , , }i i i iDx x x x  , and the position of each particle is a potential solution. When ix is brought into a fitness function, a corresponding function value can be obtained, and the position of the particle is obtained according to the obtained function value, and whether the optimal solution is determined. The velocity of the i th particle is also an D - dimensional vector, expressed as: 1 2{ , , , }i i i iDv v v v  , 1,2, ,i N  . When the i th particle has searched for the best position, which is the individual optimal solution 1 2{ , , , }i i i iDpbest p p p  so far, then the best position (global optimal solution) for this particle group is searched as 99 1 2{ , , , }Dgbest g g g  [9]. The velocity and position update formula for PSO is: 1 1 1 2 2( ) ( )k k k k k k k k id id id id d idv v c rand pbest x c rand gbest x      (5) 1k k k id id idx x v   (6) The weight  has a great influence on the global search capability of the PSO. A smaller  can enhance the local search capability of the PSO. The selection of the  value needs to be set according to the actual situation. k idv is the velocity of the d th dimension of the i th particle iterating k times. 1c and 2c are learning factors that adjust the maximum step size of the gbestp and ibestp flight directions, respectively [10]. 1rand and 2rand are random numbers between [0,1] . k idx is the position of the d th dimension of the i th particle iteration k times. idpbest is the individual optimal solution of the i th particle in the d th dimension. dgbest is the global optimal solution of the entire population in the d th dimension [11]. In order to keep the particles in the search space, the velocity of each dimension of the particles is set between max max[ , ]d dv v . If the position interval of the d th dimension of the search space is set to max max[ , ]d dx x , it is generally max maxd dv kx ( 0.1 1.0k  ), and each dimension is set as such [12,13]. 2.3. Image Segmentation The threshold segmentation method is one of the region generation methods. The main idea of the threshold segmentation method is to determine the threshold. Select the appropriate grayscale segmentation value, and compare each grayscale value in the image with that value. If it is a single threshold segmentation, the gray value in the image will be divided into two parts, one part is less than the segmentation threshold value, and the other part is greater than the division threshold value. Convert the input image f to a binary function: 1 ( , ) ( , )= 0 ( , ) f i j T g i j f i j T    , , (7) where T is the threshold. For the foreground image element ( , )=1g i j , for the background image element ( , )=0g i j . Traverse the image f . When ( , )f i j T , the segmented image pixel ( , )g i j is the foreground gray, otherwise it is the background gray. The selection of the segmentation threshold will directly affect people's acquisition of useful data in the image. The acquisition of useful information mainly lies in the description and analysis of the image, and the core of these two links is to see whether the obtained segmentation threshold is effective. This is enough to show the importance of this value in image segmentation. Threshold segmentation algorithms generally include artificial threshold segmentation and adaptive threshold segmentation. The artificial threshold segmentation algorithm mainly obtains the segmentation threshold based on human subjective judgment, and finally uses this value to perform image segmentation [14]. 3. Algorithm Design 3.1. Algorithm Thought From Theorem 2 and formula (3), we can know that the accuracy of VPRS is greater than Pawlak rough set, and the boundary region of VPRS is also smaller than Pawlak rough set. This shows that using VPRS to represent grayscale images is more accurate than Pawlak rough set, because for rough set theory, the smaller the boundary region, the more accurate the object description. Therefore, this paper uses VPRS to represent images. The domain U is formed by using all gray values of a gray image F of size N M . The lightness and darkness of a grayscale image are represented by the attribute R of the information system. A pixel value is arbitrarily selected in U as the initial segmentation threshold Th ( 0 1Th L   , 256L ) of the grayscale image. Divide U into the foreground set O and the background set B , then { ( , ) | ( , ) }O F i j U F i j Th   , { ( , ) | ( , ) }B F i j U F i j Th   , where i N , j M . Because the entire grayscale image F is inconvenient to be classified, the grayscale image F of size N M is now divided into k sub-blocks of size n m , denoted as iG ( 1 i k  ), where k N M n m   . The set { | }i iX P G P Th   represents a set in which pixel values in the i-th sub-block are larger than Th . It can be known from Definition 4 that the upper and lower approximation sets of the foreground set O and the background set B and related variables are defined by using VPRS. The upper and lower approximation sets of  (classification error [0, 0.5)  ) of the foreground set and related variables are as follows: The  -lower approximation set of iX : 1( ) { | ( , ) }k i i i iO Th G c G X   , where ( )O Th is also referred to as  -positive region, denoted as ( )POSO Th . The  -upper approximation set of iX : 1( ) { | ( , ) 1 }k i i i iO Th G c G X    . The  -boundary region of iX : 1( ) { | ( , ) 1 }k i i i iOBN Th G c G X      . The  -negative region of iX : 1( ) { | ( , ) 1 }k i i i iONEG Th G c G X    . The  -accuracy of iX : ( ( )) ( ) ( ( )) O card O Th Th card O Th     . The  -roughness of iX : ( ) 1 ( )O OTh Th   . 100 The upper and lower approximation sets of  (classification error [0, 0.5)  ) of the background set and related variables are as follows: The  -lower approximation set of iX : 1( ) { | ( , ) }k i i i i iB Th G c G G X    , where ( )B Th is also referred to as  -positive region, denoted as ( )POSB Th . The  -upper approximation set of iX : 1( ) { | ( , ) 1 }k i i i i iB Th G c G G X     . The  -boundary region of iX : 1( ) { | ( , ) 1 }k i i i i iBBN Th G c G G X       . The  -negative region of iX : 1( ) { | ( , ) 1 }k i i i i iBNEG Th G c G G X     . The  -accuracy of iX : ( ( )) ( ) ( ( )) B card B Th Th card B Th     . The  -roughness of iX : ( ) 1 ( )B BTh Th   . The above is the algorithm for grayscale image represented by VPRS. Among them, the classification error  is the core. The solution of this value relates to the following solution of the optimal segmentation threshold T of the gray image. Next, an algorithm for solving the classification error  is given. It can be known from definitions 2 and 3 that ( , )i ic G X can be understood as the majority inclusion relation of a grayscale image, and a method for solving ( , )i ic G X can be obtained. In fact, solving  has a certain relationship with majority inclusion relation. Theorem 2 can be used to obtain  corresponding to each segmentation threshold Th . According to the theoretical knowledge of VPRS, the greater the degree of dependency, the stronger the degree of dependency between attributes. Therefore, the maximum value of the VPRS dependency is used as a criterion for measuring the optimal segmentation threshold T , and the dependency of the VPRS is used to measure the target set and the background set of the grayscale image. Because the image itself has a large order of magnitude, it is less efficient to solve T using ordinary iterative methods, so we introduce the intelligent algorithm PSO to improve the efficiency of solving T . Therefore, we propose an image segmentation algorithm using VPRS maximum dependency and PSO. When the VPRS dependency is the largest, not only the corresponding segmentation threshold is the best, but the corresponding classification error  is also the best. Therefore, the VPRS dependency and  are in a one-to-one correspondence relationship. Generally,  is determined through experience, but obviously there is some blindness. Here we use VPRS theoretical knowledge and Theorem 2 to solve  , which will get effective and practical  , and the calculation process is not blind. Of course, we must also consider the actual situation for specific problems. From Definition 5, we can see that the dependency between the foreground and background sets of the image is as follows: ( ( )) ( ( )) ( ) ( )B card POSO Th card POSB Th O card U     (8) 3.2. Algorithm Steps The steps of the threshold segmentation algorithm are described below. Input: A domain U composed of all gray values of image F . Output: The optimal segmentation threshold T for grayscale image. Step 1: The domain U is divided into a target set and a background set by an initial segmentation threshold Th . Step 2: An image F of size N M is divided into several sub-blocks of size n m . Step 3: Initialize the velocity, position, and population of each particle (think of a sub-block of size n m as a particle). The maximum dependency of VPRS is used as the fitness function. Step 4: Calculates the fitness value of the current particle. Step 4.1: The classification error  of the target set and the background set of the current particle is calculated by formula (1) and theorem 2. Step 4.2: Solve ( )POSO Th and ( )POSB Th of the current particle through step 4.1. Step 4.3: Initialize the position of the current particle by step 4.2, formula (8) and step 3, and calculate the fitness value of the current particle. Step 5: Calculate the current particle dependency ( )B O through step 4.3. if ( )B O > idpbest , then ( )id Bpbest O . (Initialize the individual optimal solution) Step 6: Calculate the current particle dependency ( )B O through step 4.3. if idpbest > dgbest , then d idgbest pbest . (Initialize the local optimal solution). Step 7: The position and velocity of the current particle are evolved by formula (5), formula (6), step 5 and step 6. (Here 1 2 2c c  , 1rand and 2rand are random numbers in [0,1] , and the inertia weight is 0.6  ) Step 8: If (if) the threshold corresponding to the maximum dependency is found, the result is output and the program ends. Otherwise (else) repeat step 4, step 5, step 6 and step 7. Until the threshold corresponding to the maximum dependency is found, the result is output, and the program ends. 4. Experiment Analysis In the process of segmenting a grayscale image using the proposed algorithm, the changes in the dependency, classification error, and segmentation threshold are shown in Table 2. 101 Table 2. Variations of various variables in image segmentation Th (Segmentation threshold)  (Classification error) ( )B O (Dependency) 25 0.4754 0.0048 37 0.4702 0.0037 43 0.4765 0.0021 56 0.4518 0.0065 76 0.4534 0.0015 139 0.4831 0.0061 152 0.4989 0.0025 195 0.4624 0.0036 214 0.4812 0.0027 Only representative values were selected throughout the algorithm. It can be known from Table 2 that the theoretical process of segmenting images using the proposed algorithm is basically consistent with the actual process. In the implementation of the proposed algorithm, the maximum dependency value is used as the standard to select the optimal segmentation threshold T . It can be seen from Table 2 that the metric value is reasonable. The experimental results of image segmentation using the proposed algorithm are shown in Figure 5. The experiment also used the maximum average information entropy to segment the image for comparison. The experimental results are shown in Figure 3. Fig 1. Original image Fig 2. Histogram Fig 3. Threshold segmentation using maximum average information entropy Fig 4. Correspondence between segmentation threshold and average information entropy Fig 5. Threshold segmentation using VPRS maximum dependency. 102 Fig 6. Correspondence between segmentation threshold and dependency Fig 6 is a correspondence diagram between the dependency and the segmentation threshold. When the dependency reaches the maximum value, its corresponding segmentation threshold T = 1. The original image is segmented by using this segmentation threshold to obtain a segmentation effect image. By comparing the segmentation effect diagrams of FIG. 3 and FIG. 5, it can be seen that the segmentation effect using the maximum dependency is better than the maximum average information entropy. In order to improve the efficiency of solving the optimal segmentation threshold, PSO is used to optimize the execution process of the proposed algorithm. Here, in order to better reflect the optimization effect of PSO, the PSO is compared with the ordinary iterative method. The comparison result is shown in Table 3. Table 3. Comparison results between PSO and ordinary iterative method Algorithm Subblock size ( n m ) Is it combined with PSO? Optimal segmentation threshold (T ) Number of iterations ( n ) Algorithm running time ( s ) Maximum average information entropy —— NO 38 56 3.378123 Maximum dependency 8 8 YES 50 20 0.566854 5. Conclusion In this paper, we propose an effective image segmentation algorithm. The proposed algorithm mainly uses VPRS maximum dependency to solve the optimal segmentation threshold, and uses PSO to improve the algorithm execution efficiency. The analysis of the experimental process and the comparison of the experimental results show that the proposed algorithm has good segmentation effect and computational efficiency. At the same time, it is verified that VPRS can effectively deal with the uncertainty and ambiguity in image segmentation. Whether the proposed algorithm can perform multi-threshold segmentation and color image segmentation needs further research and confirmation. Acknowledgments 1.Research on the Application of Virtual Reality in the Roaming System of the School and Campus: A Case Study of Xinjiang University of Political Science and Law. (Xinjiang University of Political Science and Law President's Fund: XZZK2022008; Xinjiang University of Political Science and Law President's Fund: XZZK2022005.) References [1] Zhu Liangkuan, Liu Liang, Dong Xu, et al. Forest canopy image segmentation based on improved 3D Otsu method[J]. Computer Engineering. 2019, Vol. 45(No. 01), p. 253-258+263. [2] Lei Xiangxiao, Ouyang Honglin, Xiao Leyi, et al. Research on image segmentation based on equivalent 3-D entropy and whale optimization algorithm[J]. Computer Engineering. 2019, Vol. 45(No. 04), p. 217-222. [3] Nabanita Mahata, Jamuna Kanta Sing. A novel fuzzy clustering algorithm by minimizing global and spatially constrained likelihood-based local entropies for noisy 3D brain MR image segmentation[J]. Applied Soft Computing Journal. 2020, Vol. 90. [4] Xiaofeng Yue, Hongbo Zhang. Modified hybrid bat algorithm with genetic crossover operation and smart inertia weight for multilevel image segmentation[J]. Applied Soft Computing Journal. 2020, Vol. 90. [5] Zhang Wenxiu, Wu Weizhi, Liang Jiye. Rough Set Theory and Method [M]. Science Press, 2001. [6] Sun Quansen, Ji Zexuan. Fuzzy Clustering for Brain MR Image Segmentation [J]. Journal of Data Acquisition and Processing. 2016, Vol. 31(No. 1), p. 28-42. [7] Li Tingting, Jiang Zhaohui, Rao Yuan, et al. Image segmentation based on gene expression programming and spatial fuzzy clustering [J]. Journal of Image and Graphics. 2017, Vol. 22(No. 5), p. 575-583. [8] Zhang C, Pan X , Zhang S , et al. A rough set decision tree based MLP-CNN for very high resolution remotely sensed image classification[J]. Isprs International Archives of the Photogrammetry Remote Sensing & Spatial Information Sciences. 2017, p. 1451-1454. [9] Zhang Changsheng, Feng Guang, Liu Ziyu, et al. Research on improved two-dimension Otsu algorithm for SF6 pressure dial image segmentation [J]. Transducer and Microsystem Technologies. 2017, Vol. 36(No. 7), p. 8-11. [10] Zhang Yingchun, Guo He. Level set Image segmentation based on rough set and new energy formula [J]. Acta Automatica Sinica. 2015, Vol. 41(No. 11), p. 1913-1925. [11] Zhang Yongmei, Bad Kay, Xing Kuo. A method of fuzzy threshold for adaptive image segmentation [J]. Computer Measurement & Control. 2016, Vol. 24(No. 4), p. 126-128. [12] Xu Luping. Digital Image Processing [M]. Science Press, 2007. [13] Phophalia A, Mitra S K. 3D MR image denoising using rough set and kernel PCA method[J]. Magnetic Resonance Imaging. 2017, Vol. 36, p. 135. [14] Ji Z, Huang Y, Sun Q, et al. A rough set bounded spatially constrained asymmetric gaussian mixture model for image segmentation[J]. PLoS ONE. 2017, Vol. 12(No. 1), p. 697-708.