Image segmentation method based on improved whale optimization algorithm

By improving the whale algorithm and combining it with Otsu thresholding, and introducing the Levy flight mechanism and parameter c1, the problem of high computational complexity in existing image segmentation algorithms is solved, and higher quality image segmentation results are achieved.

CN117197173BActive Publication Date: 2025-11-21HEBEI GEO UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310222966.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-09
Publication Date
2025-11-21
Estimated Expiration
2043-03-09

AI Technical Summary

Technical Problem

Existing threshold-based image segmentation methods, such as the Otsu algorithm, suffer from high computational complexity and large computational cost, which affects the image segmentation quality.

Method used

By combining the improved whale algorithm with the Otsu threshold segmentation method, and introducing the Levy flight mechanism and parameter c1, the position update strategy of the whale algorithm is improved, thereby enhancing the global search capability and convergence speed.

Benefits of technology

The improved algorithm enhances the quality and accuracy of image segmentation. Experimental results demonstrate that the improved algorithm exhibits significant advantages in various image segmentation tasks, with higher peak signal-to-noise ratio and better segmentation performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117197173B_ABST
    Figure CN117197173B_ABST
Patent Text Reader

Abstract

The application discloses an image segmentation method based on an improved whale optimization algorithm, which comprises the following steps: 1, obtaining an image to be segmented; 2, setting the whale population size and the maximum number of iterations, and initializing the whale population position; 3, calculating the individual fitness value and recording the optimal individual and position; 4, judging whether the maximum number of iterations is reached, if yes, directly outputting the optimal threshold and the segmented image, if not, entering step 5; 5, updating the convergence factor a and the coefficient vectors A and C; 6, generating a random number p in the range of [0, 1] and judging whether p < 0.5 is true, if not, updating the individual position spirally, if yes, entering step 7; 7, judging whether A < l is true, if yes, updating the individual position according to the position of the optimal solution, if not, selecting a whale individual randomly and updating the individual position; 8, adding 1 to the number of iterations and returning to step 3 until the number of iterations reaches the maximum number of iterations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of image segmentation technology, specifically relating to an image segmentation method based on an improved whale algorithm. Background Technology

[0002] With the continuous development of intelligent industrial production, image segmentation has received widespread attention. Numerous image segmentation methods have emerged. Image segmentation refers to decomposing a complete image into several non-overlapping, meaningful regions with unique properties, and then extracting the target of interest based on specific needs. It is the most fundamental step in image recognition and image understanding, and the quality of the image segmentation result determines the final image processing outcome. The quality of image segmentation, in turn, depends on the image segmentation algorithm used.

[0003] Since the 1960s, numerous scholars both domestically and internationally have proposed various image segmentation algorithms, mainly including threshold-based, region-based, edge-based, and theory-based methods. Threshold-based image segmentation is the simplest, most convenient, and most widely used method. The most common threshold-based method employs binarization, dividing the image below and above the threshold into two parts. A widely used method is the Otsu method, an algorithm for determining image segmentation thresholds proposed by Japanese scholar Otsu in 1979. In principle, this method is also known as the maximum inter-class variance method, sometimes referred to as the Otsu algorithm. It divides the image into background and target parts based on the image's grayscale characteristics. The larger the inter-class variance between the background and target, the greater the difference between the two parts. Misclassifying a portion of the target as background or vice versa will reduce the difference between the two parts. Therefore, segmentation that maximizes the inter-class variance implies the minimum probability of misclassification. Although it is the best algorithm for threshold selection in image segmentation, it is simple to calculate and is not affected by image brightness and contrast. However, it still has the problems of high complexity and large amount of computation, which seriously affects the quality of image segmentation. Summary of the Invention

[0004] To address the aforementioned problems, this invention proposes an image segmentation method based on an improved whale algorithm. This method combines the improved whale algorithm with the Otsu thresholding method, using the improved whale algorithm to find the optimal threshold for image segmentation, thereby improving the segmentation quality of the image.

[0005] The technical solution for realizing the present invention is as follows:

[0006] The image segmentation method based on the improved whale algorithm is characterized by the following steps:

[0007] Step 1: Obtain the image to be segmented;

[0008] Step 2: Set the whale population size and maximum number of iterations, and initialize the whale population location;

[0009] Step 3: Calculate the individual fitness value and record the best individual and its location;

[0010] Step 4: Determine if the maximum number of iterations has been reached. If yes, output the optimal threshold directly, perform image segmentation based on the obtained optimal threshold, and output the segmented image. If no, proceed to Step 5.

[0011] Step 5: Update the convergence factor a according to formula (9), and update the coefficient vectors A and C according to formulas (7) and (8):

[0012] (7)

[0013] (8)

[0014] (9)

[0015] Where t is the current iteration number, t max The maximum number of iterations, It is a random vector between [0,1].

[0016] Step 6: Generate a random number p in the range [0,1] and determine whether p < 0.5 is true. If not, update the individual position in a spiral manner; if true, proceed to step 7.

[0017] Step 7: Determine If the condition is met, the individual position is updated based on the position of the optimal solution; otherwise, a whale individual is randomly selected, and its position is updated.

[0018] Step 8: Increment the iteration count t by 1 and return to step 3 until the iteration count reaches the maximum iteration count.

[0019] Furthermore, the formula for spirally updating the individual position in step 6 is:

[0020] (12)

[0021] Where X represents the location of the whale population; Let X be the current position (X, Y) of the whale and the position of the optimal solution. The absolute value of the distance between them; b It is a constant used to define the shape of the helix; l It is a random number in the range [-1, 1].

[0022] Furthermore, the specific operational steps of step 7 include:

[0023] Step 71: Based on the obtained coefficient vector A, determine... Check if the condition is met. If it is met, proceed to step 72; if it is not met, proceed to step 73.

[0024] Step 72: Update the individual position according to the position of the optimal solution using formula (11):

[0025] (10)

[0026] (11)

[0027] in, The distance between the whale's current location and its target prey is t; t is the current iteration number. This is the position vector of the whale's optimal solution so far; It is the current position vector of the whale; For coefficient vectors;

[0028] Step 73: Randomly select a whale individual according to formula (4), and update the whale individual's position according to formula (6):

[0029] (4)

[0030] (5)

[0031] (6)

[0032] Where L is the total number of iterations of the algorithm; l c1 is the current iteration number; c2 is a random number between [0,1]. ub and lb These are the maximum and minimum vectors in the search space, respectively.

[0033] Compared with the prior art, the present invention has the following advantages:

[0034] First, this invention combines the improved whale algorithm with the Otsu threshold segmentation method, using the improved whale algorithm to find the optimal threshold for image segmentation, thereby improving the segmentation quality of the image.

[0035] Secondly, this invention applies the Levy flight mechanism to the traditional whale algorithm, which enables individual whales to change their positions over a wide range during random search, thereby improving the global search capability of the whale algorithm. It introduces the Levy flight feature in the random search phase of the whale and improves the traditional position update parameter by introducing parameter c1. c1 can gradually increase with the number of iterations, thereby enabling the whale algorithm to gradually converge and find a better solution.

[0036] Finally, by comparing the image segmentation results of the proposed method with those of the Whale Algorithm (WOA), Slug Group Algorithm (SSA), and Otsu's method (OTSU), the experimental results show that the proposed method has significant advantages, can obtain more accurate segmentation thresholds, and effectively improves the segmentation quality of images. Attached Figure Description

[0037] Figure 1 For Levi's flight trajectory;

[0038] Figure 2 This is a flowchart of the algorithm proposed in this invention;

[0039] Figures 3a-3f These are the original images of the six grayscale images selected in the embodiment;

[0040] Figures 4a-4d The results of "lena" image segmentation using four algorithms, LWOA, WOA, SSA, and OTSU, with a threshold of 3, are shown.

[0041] Figures 5a-5d The results of "lena" image segmentation for four algorithms, LWOA, WOA, SSA and OTSU, with a threshold of 4, are shown respectively.

[0042] Figures 6a-6d The results of "baboon" image segmentation for four algorithms, LWOA, WOA, SSA, and OTSU, with a threshold of 3, are shown respectively.

[0043] Figures 7a-7d The results of "baboon" image segmentation for four algorithms, LWOA, WOA, SSA, and OTSU, with a threshold of 4, are shown.

[0044] Figures 8a-8d The images show the "boat" image segmentation results for four algorithms: LWOA, WOA, SSA, and OTSU, with a threshold of 3.

[0045] Figures 9a-9d The results of "boat" image segmentation using four algorithms—LWOA, WOA, SSA, and OTSU—with a threshold of 4 are shown.

[0046] Figures 10a-10d The images show the "cameraman" image segmentation results for four algorithms: LWOA, WOA, SSA, and OTSU, with a threshold of 3.

[0047] Figures 11a-11d The images show the "cameraman" image segmentation results for four algorithms: LWOA, WOA, SSA, and OTSU, with a threshold of 4.

[0048] Figures 12a-12d The results of "house" graph segmentation for four algorithms, LWOA, WOA, SSA, and OTSU, with a threshold of 3, are shown respectively.

[0049] Figures 13a-13d The results of "house" graph segmentation for four algorithms, LWOA, WOA, SSA, and OTSU, with a threshold of 4, are shown.

[0050] Figures 14a-14d The images show the segmentation results of the "goldhill" image using four algorithms: LWOA, WOA, SSA, and OTSU, with a threshold of 3.

[0051] Figures 15a-15d The images show the segmentation results of the "goldhill" image using four algorithms: LWOA, WOA, SSA, and OTSU, with a threshold of 4.

[0052] Figures 16a-16f The fitness curves for the six images "lena", "baboon", "boat", "cameraman", "house", and "goldhill" are shown below, with a threshold of 4. Detailed Implementation

[0053] To enable those skilled in the art to better understand the technical solutions of the present invention, the technical solutions of the present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0054] The core idea of ​​this invention is to apply the Levy flight mechanism to the whale algorithm, thereby improving the traditional whale algorithm. The improved whale algorithm enables individual whales to change their positions over a wide range during random searches, thus improving the global search capability of the whale algorithm.

[0055] 1. Levi Flight

[0056] Lévy flight is a special method using stochastic step sizes. It features small-range searches and large-range jumps. Many studies have shown that Lévy flight phenomena exist in nature. Examples include the random motion trajectories of molecules and the food-hunting trajectories of wasps and fruit flies. The trajectory of Lévy flight is as follows: Figure 1 As shown, its step size is mostly small and the distance between each two steps is not equal, and occasionally large fluctuations occur.

[0057] The formula for Levi's flight is:

[0058] (1)

[0059] in, For constant parameters, Follows a normal distribution ;

[0060] Generate a random step size s that follows a Lévy distribution using the Mantegna algorithm:

[0061] (2)

[0062] in, is a constant and =1.5; All follow a normal distribution , .

[0063] and The variance is expressed as:

[0064] (3)

[0065] in, It is the standard Gamma function. To represent factorial;

[0066] 2. Whale Optimization Algorithm (WOA) Incorporating Levy Flight Characteristics

[0067] The Whale Optimization Algorithm (WOA) has the advantages of simple computation and fast solution speed. Its convergence speed is relatively fast in the early stages of iteration. However, as the number of iterations increases, the searched individuals are likely to cluster, leading to a decrease in the diversity of the search group and causing it to fall into local optima, resulting in premature convergence. Therefore, to improve the global search capability of the WOA algorithm, this invention introduces the Levy flight feature in the whale random search stage. The Levy flight formula is given by equation (4), and parameter c1 is introduced:

[0068] (4)

[0069] (5)

[0070] (6)

[0071] in, Expression (1); L is the total number of iterations of the algorithm; L is the total number of iterations of the algorithm; l c1 is the current iteration number; c2 is a random number between [0,1]. ub and lb These are the maximum and minimum vectors in the search space, respectively.

[0072] Since c1 in formula (5) gradually increases with the number of iterations, the WOA algorithm gradually converges. Finally, the position of the next generation of whales is updated by formula (6). Therefore, it can be seen that by introducing the Levy flight strategy and parameter c1, the global search capability of WOA can be improved, and timely convergence to find the optimal solution can be guaranteed.

[0073] 3. Image segmentation algorithm based on improved whale algorithm

[0074] The specific steps of the image segmentation algorithm based on the improved whale algorithm (LWOA) are shown in Table 1:

[0075] Table 1. Description of LWOA Algorithm

[0076]

[0077]

[0078] Combined with Table 1 and the attached table Figure 2 The LWOA algorithm flowchart shown below indicates that it includes the following steps:

[0079] Step 1: Obtain the image to be segmented;

[0080] Step 2: Set the whale population size and maximum number of iterations, and initialize the whale population location;

[0081] Step 3: Calculate the individual fitness value and record the best individual and its location;

[0082] Step 4: Determine if the maximum number of iterations has been reached. If yes, output the optimal threshold directly, perform image segmentation based on the obtained optimal threshold, and output the segmented image. If no, proceed to Step 5.

[0083] Step 5: Update the convergence factor a according to formula (8), and update the coefficient vectors A and C according to formulas (7) and (8):

[0084] (7)

[0085] (8)

[0086] (9)

[0087] Step 6: Generate a random number p in the range [0,1] and determine whether p < 0.5 is true. If not, update the individual position spirally according to formula (12); if true, proceed to step 7.

[0088] (12)

[0089] Step 7: Determine If the condition is met, the individual position is updated according to the position of the optimal solution in formula (11); if the condition is not met, a whale individual is randomly selected according to formula (4), and the individual position is updated according to formula (6).

[0090] (10)

[0091] (11)

[0092] in, The distance between the whale's current location and its target prey is t; t is the current iteration number. This is the position vector of the whale's optimal solution so far; It is the current position vector of the whale; For coefficient vectors;

[0093] Step 8: Increment the iteration count t by 1 and return to step 3 until the iteration count reaches the maximum iteration count.

[0094] Example

[0095] To verify the superiority of the LWOA algorithm in threshold segmentation studied in this paper, simulation experiments were conducted using MATLAB R2018a software. Six grayscale images, "lena", "baboon", "boat", "cameraman", "house", and "goldhill", were selected for the experiment. The LWOA algorithm, along with WOA, SSA, and OTSU algorithms, were used for threshold segmentation at 3, 4, and 5 thresholds. The original images selected for the experiment are shown below. Figures 3a-3f As shown.

[0096] 1. Parameter settings for the four algorithms

[0097] As shown in Table 2, the parameter assignments for the above four algorithms are as follows:

[0098] Table 2 Parameters of each algorithm

[0099]

[0100] 2. Segmentation results and comparative experiments with threshold values ​​of 3, 4, and 5 (dim).

[0101] (1) Segmentation performance indicators

[0102] This experiment uses Peak Signal-to-Noise Ratio (PSNR), Best Fitness Value, and Best Threshold as evaluation metrics for image segmentation results. PSNR, the ratio of maximum signal power to noise power that affects signal fidelity, is an objective standard for evaluating images at the pixel level. PSNR (dB) is measured by the Mean Squared Error (MSE), and the calculation formula is as follows:

[0103]

[0104]

[0105] In the formula, I and K are the images before and after segmentation, respectively. According to the definition, the smaller the noise, the higher the peak signal-to-noise ratio, and the better the image segmentation effect.

[0106] (2) Comparison of segmentation results

[0107] Tables 3-5 present the segmentation data for the four algorithms with thresholds of 3, 4, and 5, respectively. Since a higher PSNR value indicates better image segmentation, the highest PSNR for each image under different algorithms is highlighted. Observing the PSNR values, it can be seen that when the threshold is 3, for the images "lena" and "cameraman," LWOA's PSNR is 17.4711 and 20.1395, respectively, higher than the peak signal-to-noise ratio of other algorithms, but the optimal fitness values ​​are basically the same. For the other four images, LWOA, SSA, and WOA have the same PSNR, and all are higher than OTSU. Therefore, the LWOA algorithm has certain advantages.

[0108] When the threshold is 4, for the first five images, LWOA's PSNR values ​​are generally higher than the other three algorithms, and its optimal fitness value is also generally the highest. For the sixth image, "goldhill," the PSNR of LWOA is the same as that of SSA and WOA. These data demonstrate that the algorithm of this invention achieves better segmentation results.

[0109] When the threshold is 5, except for "cameraman", LWOA's PSNR value is higher than other algorithms for the segmentation of the last five images. In summary, with a few exceptions, the algorithm proposed in this invention can achieve the highest PSNR, which proves the superiority of the proposed algorithm in image segmentation.

[0110] Table 3. Segmentation results with a threshold of 3.

[0111]

[0112]

[0113] Table 4. Segmentation results with a threshold of 4.

[0114]

[0115]

[0116] Table 5. Segmentation results with a threshold of 5.

[0117]

[0118]

[0119] To more intuitively observe the segmentation effect of this algorithm, Figures 4a to 15d This represents the segmentation results of four algorithms on six images when the threshold values ​​are 3 and 4. Each image, from the first to the fourth, shows the segmentation results of the four algorithms: LWOA(a), WOA(b), SSA(c), and OTSU(d).

[0120] The image of "lena" primarily extracts the person and the mirror. Observe them separately. Figures 4a-4d and Figures 5a-5d As can be seen, LWOA(a) significantly outperforms other algorithms in segmenting the woman's face, hair, mirror edges, and image background. The LWOA algorithm proposed in this invention provides more detailed segmentation of the target region, while other algorithms suffer from information loss in the image. As the number of thresholds increases, the overall image becomes brighter, and the segmentation of hair, facial contours, and background becomes more refined.

[0121] "baboon" primarily extracts the baboon's cheeks, hair, and whiskers. Comparisons are then made. Figures 6a-6d and Figures 7a-7d As can be seen, LWOA(a) provides clearer segmentation of the nose, right-side hair, and beard, while other algorithms exhibit over-segmentation or information loss in these areas. This demonstrates that the proposed LWOA algorithm offers more refined image segmentation. Furthermore, a higher number of segmentation thresholds results in finer local segmentation, a brighter image, and higher overall segmentation quality.

[0122] "boat" requires extracting the clouds in the sky, the mast, and the overall outline of the boat. Figures 8a-8d The four algorithms produce similar segmentations of the ship hull and clouds, but LWOA (a) provides a clearer segmentation of the sea level and preserves the information of the original image very well. Figures 9a-9d In comparison, this algorithm provides more refined processing of clouds, accurately depicting their distribution and better matching the information in the original image. (Image comparison) Figures 8a-8d and Figures 9a-9d Increasing the threshold number reveals a more vivid and detailed overall image segmentation.

[0123] "Cameraman" primarily segments out the facial contours of the person, the camera and tripod, the lawn, and the background buildings. Figures 10a-10d From this, we can see that LWOA ( Figure 10a It is significantly better than other algorithms at segmenting the lines of men's pants, the background, and the grass. Figures 11a-11dCompared with other algorithms, the LWOA algorithm provides more complete segmentation of the lawn and background buildings, giving it a certain advantage. Figures 10a-10d and Figures 11a-11d It can be seen that increasing the number of thresholds results in more precise segmentation of character clothing, background, and lawn.

[0124] The image "house" primarily extracts the doors, windows, and overall outline of the house. Figures 12a-12d Among them, the first three algorithms are significantly better than the fourth. Figure 12d The treatment of the shadowed areas of the walls and eaves is somewhat rough in its segmentation. Figures 13a-13d In the image segmentation, LWOA segmented the window outline relatively evenly, and clearly defined the light and dark areas of the eaves shadows, thus preserving the information of the original image well. This demonstrates the advantages of this algorithm in image segmentation.

[0125] The image "goldhill" is segmented into houses, trees, and a fence in the lower right corner. Figures 14a-14d In the comparison, the LWOA algorithm provides a more complete segmentation of the white house walls, with clearer depictions of the trees and fences in the background. Figures 15a-15d In the comparison, the LWOA algorithm provides a clearer segmentation of the fence, with each fence clearly defined. This demonstrates that the proposed algorithm achieves better segmentation results. Figures 14a-14d and Figures 15a-15d Increasing the number of thresholds can make the segmented image clearer and brighter overall.

[0126] In summary, by comparing the optimal fitness value and peak signal-to-noise ratio (PSNR) of the algorithms, it can be seen that, with a few exceptions, the LWOA algorithm has the highest optimal fitness value and PSNR, significantly outperforming other algorithms. A comparison of the image segmentation results also demonstrates that the LWOA algorithm achieves good image segmentation performance.

[0127] 3. Analysis of convergence and optimization capabilities

[0128] To demonstrate the algorithm's optimization and convergence capabilities, Figures 16a-16e Fitness curves for six images with a threshold of 4 were plotted. Since the fitness values ​​of some algorithms are similar, the number of iterations on the x-axis was retained until the image curves were clearer for better observation.

[0129] from Figures 16a-16e It can be seen that the LWOA algorithm consistently achieves the highest fitness value, demonstrating its superior optimization ability. From... Figure 16fIt can be seen that the LWOA algorithm is the first to reach the optimal fitness value and converges first, followed by the SSA and WOA algorithms, while the OTSU algorithm gets stuck in a local optimum. This proves that the LWOA algorithm has good convergence ability. In the other images, the convergence ability of the LWOA and WOA algorithms is similar, while the convergence ability of the SSA and OTSU algorithms is poor. Therefore, it is proven that the LWOA algorithm proposed in this invention has good convergence and optimization capabilities.

[0130] Contents not described in detail in this specification are existing technologies known to those skilled in the art. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. An image segmentation method based on an improved whale algorithm, characterized in that, Includes the following steps: Step 1: Obtain the image to be segmented; Step 2: Set the whale population size and maximum number of iterations, and initialize the whale population location; Step 3: Calculate the individual fitness value and record the best individual and its location; Step 4: Determine if the maximum number of iterations has been reached. If yes, output the optimal threshold directly, perform image segmentation based on the obtained optimal threshold, and output the segmented image. If no, proceed to Step 5. Step 5: Update the convergence factor a according to formula (9), and update the coefficient vectors A and C according to formulas (7) and (8): (7) (8) (9) Where t is the current iteration number, t max The maximum number of iterations, It is a random vector between [0,1]. Step 6: Generate a random number p in the range [0,1] and determine whether p < 0.5 is true. If not, update the individual position in a spiral manner; if true, proceed to step 7. Step 7: Determine If the condition is met, the individual position is updated based on the position of the optimal solution; otherwise, a whale individual is randomly selected, and its position is updated. Step 8: Increment the iteration count t by 1, and return to step 3 until the iteration count reaches the maximum iteration count; The specific steps in step 7 include: Step 71: Based on the obtained coefficient vector A, determine... Check if the condition is met. If it is met, proceed to step 72; if it is not met, proceed to step 73. Step 72: Update the individual position according to the position of the optimal solution using formula (11): (10) (11) in, The distance between the whale's current location and its target prey is t; t is the current iteration number. This is the position vector of the whale's optimal solution so far; It is the current position vector of the whale; For coefficient vectors; Step 73: Randomly select a whale individual according to formula (4), and update the whale individual's position according to formula (6): (4) (5) (6) Where L is the total number of iterations of the algorithm; l c1 is the current iteration number; c2 is a random number between [0,1]. ub and lb These are the maximum and minimum vectors in the search space, respectively.

2. The image segmentation method based on the improved whale algorithm according to claim 1, characterized in that, The formula for spirally updating the individual position in step 6 is: (12) Where X represents the location of the whale population; Let X be the current position (X, Y) of the whale and the position of the optimal solution. The absolute value of the distance between them; b It is a constant used to define the shape of the helix; l It is a random number in the range [-1, 1].

Citation Information

Patent Citations

  • Image segmentation method based on Harris eagle optimization algorithm

    CN110827299A

  • Image segmentation method based on sparrow search algorithm, electronic equipment and storage medium

    CN115272193A