# Color Image Quantization Based on the Artificial Bee Colony and Accelerated K-means Algorithms

## Abstract

**:**

## 1. Introduction

## 2. Related Works

#### 2.1. Artificial Bee Colony (ABC) Algorithm

_{i}(i = 0, 1, 2, …, SN − 1) is a K-dimensional vector. Here, K is the color number of a color palette.

_{i}is produced by the i-th employed bee as follows:

_{t}is a food source selected randomly, j is selected from the set {0, 1, 2, …, K − 1}, and ${\phi}_{ij}$ is a random number within the range [−1, 1]. In the onlooker bee phase, each onlooker bee selects a food source depending on prob

_{i}which is calculated by the following expression:

_{i}) is the fitness value of the solution s

_{i}. Then, the onlooker bees try to improve the solutions by using Equation (1).

Algorithm 1: ABC algorithm [12] |

Step 1: Generate the initial population s_{i}, i = 0, 1, 2, …, SN − 1trial _{i} = 0, i = 0, 1, 2, …, SN − 1. In the ABC algorithm, trial is a vector holding trial numbersthrough which solutions cannot be improved Set cycle to 1 Step 2: Evaluate the fitness fitness(s _{i}) of the population and memorize the best solution so farRepeat Step 3: Employed bee phase Step 4: Compute the values prob _{i} (i = 0, 1, 2, …, SN − 1) by using Equation (2)Step 5: Onlooker bee phase Step 6: Memorize the best solution so far Step 7: Scout bee phase cycle = cycle + 1 Until cycle ≤ ABC_cycle |

#### 2.2. Mean-Distance-Ordered Partial Codebook Search (MPS) Algorithm

_{min}denotes the minimal SED between the color pixel x and the closest color c

_{min}found so far. The inequality d

_{min}< SED(x,c) can be derived from Equations (5) and (6), and thus the palette color c cannot be the closest color.

## 3. Proposed Color Image Quantization Algorithm

#### 3.1. Generate N Initial Colors

#### 3.2. Select K Colors by an ABC Algorithm

#### 3.2.1. Representation of Solutions and Fitness Function

_{i}(i = 0, 1, 2, …, SN − 1) is generated, where s

_{i}= (s

_{i}

_{,0}, s

_{i}

_{,1}, s

_{i}

_{,2},…, s

_{i}

_{,K−1}), s

_{i}

_{,}

_{j}is an integer number and the 0 ≤ s

_{i}

_{,}

_{j}< s

_{i}

_{,}

_{j}

_{+1}≤ N − 1 for j = 0, 1, 2,…, K − 2. Solution s

_{i}indicates that the set of initial palette colors is {initialc[s

_{i}

_{,0}], initialc[s

_{i}

_{,1}], initialc[s

_{i}

_{,2}], …,initialc[s

_{i}

_{,K−1}]}. Then, the fitness, fitness(s

_{i}), of a solution s

_{i}is defined as

_{i}) = min{SED(initialc[j], initialc[s

_{i}

_{,0}]), SED(initialc[j], initialc[s

_{i}

_{,1}]), …, SED(initialc[j], initialc[s

_{i}

_{,K−1}])}.

#### 3.2.2. Generation of a New Solution v_{i}

_{i}= (s

_{i}

_{,0}, s

_{i}

_{,1}, s

_{i}

_{,2}, …, s

_{i}

_{,K−1}) be the present solution, while s

_{t}= (s

_{t}

_{,0}, s

_{t}

_{,1}, s

_{t}

_{,2}, …,s

_{t}

_{,K−1}) is the randomly selected solution. The proposed method will generate the new solution v

_{i}. The new solution v

_{i}is the same as s

_{i}except that s

_{i}

_{,j}is replaced by v

_{i}

_{,j}, where j is selected from the set {0, 1, 2,…, K − 1}.

_{i}

_{,j}(Algorithm 2) is computed by the following steps:

Algorithm 2: The steps of computing the value of v_{i}_{,j} |

Step 1: Range1 = s_{i}_{,j} − abs(s_{i}_{,j} − s_{t}_{,j}),Range2 = s _{i}_{,j} + abs(s_{i}_{,j} − s_{t}_{,j}), If (Range1 < 0) { Range1 = 0; } If (Range2 > (N − 1)) { Range2 = N − 1; } Step 2: SetX = {}; for (y = Range1; y ≤ Range2; y++) { If (y is not an element of s _{i}) SetX = SetX ∪ {y}; }Step 3: If (SetX == {}) { v _{i}_{,j} = s_{i}_{,j}; } else { Assume SetX = { y _{0}, y_{1}, …, y_{m−1}}, the probability of the value of v_{i}_{,j} is set to y_{r} beinginitialn(y _{r})/(initialn[y_{0}] + initialn[y_{1}] +… + initialn[y_{m−1}]) for r = 0, 1, …, m − 1; } |

#### 3.2.3. The Search Process

_{i}by the method described in Section 3.2.2. If fitness(v

_{i}) > fitness(s

_{i}) then s

_{i}is replaced by v

_{i}and trial

_{i}is set to 0 else trial

_{i}= trial

_{i}+ 1. In the onlooker bee phase, each onlooker bee which selects a solution s

_{i}depending on prob

_{i}also produces a new solution v

_{i}by the method described in Section 3.2.2. If fitness(v

_{i}) > fitness(s

_{i}) then s

_{i}is replaced by v

_{i}and trial

_{i}is set to 0 else trial

_{i}= trial

_{i}+1. In the scout bee phase, the scout bee randomly produces the new solution to replace s

_{i}if the trial

_{i}of solution s

_{i}is more than the parameter ‘limit’. In this study, the value of the parameter ‘limit’ is set to 10. The ABC algorithm is finished if the criterion cycle > ABC_cycle is satisfied. The best solution found so far is output and it represents the initial palette in this study.

#### 3.3. Accelerated K-means Algorithm

Algorithm 3: Accelerated K-means algorithm for color image quantization |

Step 1: The initial palette is generated by selecting K colors from the N initial colors based on an ABC algorithm. Set cycle to 1 Step 2: For each sampled color pixel in the color image, the closest color in the palette is efficiently determined by the MPS algorithm. If the index value of its closest palette color is j, the sampled color pixel is classified into the j-th group. Step 3: The mean values of these K groups are computed. These K values are sorted in the ascending order of their means in order to generate the new color palette. cycle = cycle + 1 Step 4: If the stopping criterion cycle > K_means_cycle is satisfied, then the algorithm stops. Otherwise, go to Step 2. |

## 4. Experimental Results

#### 4.1. The Effect of the Algorithm Parameters

#### 4.2. Comparison with the Method Proposed by Pérez-Delgado

## 5. Conclusions

## Funding

## Acknowledgments

## Conflicts of Interest

## References

- Gonzalez, R.C.; Woods, R.E. Digital Image Processing, 4th ed.; Pearson: New York, NY, USA, 2018. [Google Scholar]
- Hsieh, I.S.; Fan, K.C. An adaptive clustering algorithm for color quantization. Pattern Recognit. Lett.
**2000**, 21, 337–346. [Google Scholar] [CrossRef] - Omran, M.G.; Engelbrecht, A.P.; Salman, A. A color image quantization algorithm based on particle swarm optimization. Informatica
**2005**, 29, 261–269. [Google Scholar] - Hu, Y.C.; Lee, M.G. K-means-based color palette design scheme with the use of stable flags. J. Electron. Imaging
**2007**, 16. [Google Scholar] [CrossRef] - Celebi, M.E. Improving the performance of k-means for color quantization. Image Vis. Comput.
**2011**, 29, 260–271. [Google Scholar] [CrossRef] [Green Version] - Su, Q.; Hu, Z. Color image quantization algorithm based on self-adaptive differential evolution. Comput. Intell. Neurosci.
**2013**, 2013. [Google Scholar] [CrossRef] [Green Version] - El-Said, S.A. Image quantization using improved artificial fish swarm algorithm. Soft Comput.
**2015**, 19, 2667–2679. [Google Scholar] [CrossRef] - Schaefer, G.; Nolle, L. A hybrid color quantization algorithm incorporating a human visual perception model. Comput. Intell.
**2015**, 31, 684–698. [Google Scholar] [CrossRef] - Pérez-Delgado, M.L. Colour quantization with ant-tree. Appl. Soft Comput.
**2015**, 36, 656–669. [Google Scholar] [CrossRef] - Ueda, Y.; Koga, T.; Suetake, N.; Uchino, E. Color quantization method based on principal component analysis and linear discriminant analysis for palette-based image generation. Opt. Rev.
**2017**, 24, 741–756. [Google Scholar] [CrossRef] - Pérez-Delgado, M.L. Color image quantization using the shuffled-frog leaping algorithm. Eng. Appl. Artif. Intell.
**2019**, 79, 142–158. [Google Scholar] [CrossRef] - Karaboga, D.; Basturk, B. A powerful and efficient algorithm for numerical function optimization: Artificial bee colony (ABC) algorithm. J. Glob. Optim.
**2007**, 39, 459–471. [Google Scholar] [CrossRef] - Karaboga, D.; Basturk, B. On the performance of artificial bee colony (ABC) algorithm. Appl. Soft Comput.
**2008**, 8, 687–697. [Google Scholar] [CrossRef] - Karaboga, D.; Akay, B. A comparative study of artificial bee colony algorithm. Appl. Math. Comput.
**2009**, 214, 108–132. [Google Scholar] [CrossRef] - Karaboga, D.; Ozturk, C. Neural networks training by artificial bee colony algorithm on pattern classification. Neural Netw. World
**2009**, 19, 279–292. [Google Scholar] - Karaboga, D.; Ozturk, C. A novel clustering approach: Artificial bee colony (ABC) algorithm. Appl. Soft Comput.
**2011**, 11, 652–657. [Google Scholar] [CrossRef] - Draa, A.; Bouaziz, A. An artificial bee colony algorithm for image contrast enhancement. Swarm Evol. Comput.
**2014**, 16, 69–84. [Google Scholar] [CrossRef] - Ozturk, C.; Hancer, E.; Karaboga, D. A novel binary artificial bee colony algorithm based on genetic operators. Inf. Sci.
**2015**, 297, 154–170. [Google Scholar] [CrossRef] - Huang, S.C. High-quality codebook generation of vector quantization using the HT-ABC-LBG algorithm. J. Inf. Sci. Eng.
**2018**, 34, 81–102. [Google Scholar] - Saad, E.; Elhosseini, M.A.; Haikal, A.Y. Culture-based artificial bee colony with heritage mechanism for optimization of wireless sensors network. Appl. Soft Comput.
**2019**, 79, 59–73. [Google Scholar] [CrossRef] - Chen, X.; Tianfield, H.; Li, K. Self-adaptive differential artificial bee colony algorithm for global optimization problems. Swarm Evol. Comput.
**2019**, 45, 70–91. [Google Scholar] [CrossRef] [Green Version] - Gorkemli, B.; Karaboga, D. A quick semantic artificial bee colony programming (qsABCP) for symbolic regression. Inf. Sci.
**2019**, 502, 346–362. [Google Scholar] [CrossRef] - Ra, S.W.; Kim, J.K. A fast mean-distance-ordered partial codebook search algorithm for image vector quantization. IEEE Trans. Circuits Syst. II Analog. Digit. Signal. Process.
**1993**, 40, 576–579. [Google Scholar] [CrossRef] - Hu, Y.C.; Su, B.H.; Tsou, C.C. Fast VQ codebook search algorithm for grayscale image coding. Image Vis. Comput.
**2008**, 26, 657–666. [Google Scholar] [CrossRef]

**Figure 1.**(

**a**) The sorted palette of K colors; (

**b**) the searching order of colors if the color pixel x = (100, 50, 80).

**Figure 5.**(

**a**) The Lena image, (

**b**) 32 colors quantized image, (

**c**) 64 colors quantized image, (

**d**) 128 colors quantized image, (

**e**) 256 colors quantized image.

**Figure 6.**(

**a**) The Baboon image, (

**b**) 32 colors quantized image, (

**c**) 64 colors quantized image, (

**d**) 128 colors quantized image, (

**e**) 256 colors quantized image.

**Figure 7.**(

**a**) The Pepper image, (

**b**) 32 colors quantized image, (

**c**) 64 colors quantized image, (

**d**) 128 colors quantized image, (

**e**) 256 colors quantized image.

**Figure 8.**(

**a**) The Lake image, (

**b**) 32 colors quantized image, (

**c**) 64 colors quantized image, (

**d**) 128 colors quantized image, (

**e**) 256 colors quantized image.

**Figure 9.**(

**a**) The Airplane image, (

**b**) 32 colors quantized image, (

**c**) 64 colors quantized image, (

**d**) 128 colors quantized image, (

**e**) 256 colors quantized image.

**Table 1.**Results of the proposed method with PixelThr = 30, SN = 20, ABC_cycle = 15 and K_means_cycle = 20. (Sr: sampling rate, MSE

_{a}: average mean square error (MSE), T: average computation time (milliseconds)).

K = 32 | K = 64 | K = 128 | K = 256 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Image | Sr | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T |

Lena | 1.0 | 121.33 | 1.52 | 527 | 73.84 | 1.02 | 848 | 47.53 | 0.53 | 1460 | 31.31 | 0.12 | 2484 |

0.25 | 121.36 | 1.67 | 170 | 74.13 | 0.89 | 252 | 47.66 | 0.43 | 414 | 31.71 | 0.14 | 644 | |

0.125 | 121.66 | 1.83 | 93 | 74.17 | 0.73 | 156 | 48.03 | 0.48 | 237 | 32.03 | 0.11 | 422 | |

0.0625 | 122.14 | 1.32 | 75 | 74.5 | 0.81 | 110 | 48.58 | 0.41 | 168 | 32.68 | 0.11 | 275 | |

Baboon | 1.0 | 382.57 | 4.7 | 835 | 242.19 | 1.7 | 1226 | 155.61 | 1.5 | 1962 | 100.16 | 0.8 | 3259 |

0.25 | 383.01 | 5.0 | 260 | 242.68 | 2.9 | 413 | 155.95 | 1.9 | 677 | 100.52 | 0.8 | 1145 | |

0.125 | 383.42 | 4.7 | 193 | 242.76 | 2.5 | 273 | 157.06 | 1.6 | 461 | 101.85 | 0.8 | 783 | |

0.0625 | 387.06 | 4.3 | 146 | 244.46 | 1.9 | 218 | 158.06 | 1.4 | 351 | 103.44 | 0.8 | 606 | |

Peppers | 1.0 | 236.77 | 3.2 | 659 | 141.73 | 4.0 | 1029 | 86.45 | 3.3 | 1644 | 55.46 | 0.4 | 2876 |

0.25 | 237.31 | 3.0 | 207 | 141.95 | 3.9 | 331 | 86.51 | 3.5 | 539 | 56.05 | 0.4 | 908 | |

0.125 | 237.87 | 4.6 | 129 | 141.72 | 2.7 | 209 | 87.37 | 3.3 | 318 | 56.81 | 0.3 | 565 | |

0.0625 | 239.28 | 6.9 | 87 | 143.03 | 3.5 | 137 | 88.34 | 3.2 | 237 | 58.07 | 0.4 | 408 | |

Lake | 1.0 | 207.73 | 3.2 | 651 | 134.88 | 1.6 | 1001 | 87.41 | 1.4 | 1538 | 57.09 | 0.5 | 2665 |

0.25 | 208.38 | 2.6 | 217 | 135.19 | 1.6 | 343 | 88.58 | 1.1 | 514 | 57.71 | 0.6 | 818 | |

0.125 | 208.95 | 3.6 | 120 | 135.83 | 1.8 | 192 | 89.1 | 0.9 | 316 | 58.57 | 0.8 | 532 | |

0.0625 | 210.29 | 3.5 | 100 | 137.59 | 2.4 | 132 | 90.45 | 1.0 | 222 | 60.24 | 0.7 | 387 | |

Airplane | 1.0 | 68.56 | 3.8 | 322 | 41.91 | 2.5 | 380 | 26.52 | 1.1 | 601 | 18.19 | 0.4 | 1136 |

0.25 | 68.97 | 2.6 | 105 | 41.62 | 2.0 | 123 | 27.11 | 1.0 | 224 | 18.46 | 0.4 | 440 | |

0.125 | 69.69 | 3.5 | 56 | 42.26 | 2.1 | 83 | 27.05 | 1.4 | 146 | 18.82 | 0.4 | 292 | |

0.0625 | 70.17 | 3.6 | 51 | 42.49 | 1.8 | 63 | 27.75 | 1.0 | 108 | 19.05 | 0.5 | 241 |

Image | K | Computation Time for Initial Palette Generation | Computation Time for Clustering by Accelerated K-means Algorithm | Total Computation Time |
---|---|---|---|---|

Lena | 32 | 31 | 62 | 93 |

64 | 46 | 110 | 156 | |

128 | 78 | 159 | 237 | |

256 | 141 | 281 | 422 | |

Baboon | 32 | 78 | 115 | 193 |

64 | 117 | 156 | 273 | |

128 | 227 | 234 | 461 | |

256 | 409 | 374 | 783 | |

Peppers | 32 | 63 | 66 | 129 |

64 | 84 | 125 | 209 | |

128 | 115 | 203 | 318 | |

256 | 222 | 343 | 565 | |

Lake | 32 | 52 | 68 | 120 |

64 | 78 | 114 | 192 | |

128 | 146 | 170 | 316 | |

256 | 224 | 308 | 532 | |

Airplane | 32 | 26 | 30 | 56 |

64 | 42 | 41 | 83 | |

128 | 78 | 68 | 146 | |

256 | 167 | 125 | 292 |

**Table 3.**Results of the method proposed by Pérez-Delgado [11]. (Sr: sampling rate, MSE

_{a}: average MSE, T: average computation time (milliseconds)).

K = 32 | K = 64 | K = 128 | K = 256 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Image | Sr | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T | MSE_{a} | S.D. | T |

Lena | 1.0 | 120.37 | 1.21 | 8654 | 73.76 | 0.98 | 17022 | 47.64 | 0.57 | 35134 | 31.06 | 0.24 | 70477 |

0.5 | 120.50 | 0.74 | 4579 | 74.32 | 1.52 | 8589 | 47.32 | 0.40 | 17888 | 31.19 | 0.39 | 35801 | |

0.2 | 121.27 | 1.63 | 1908 | 73.87 | 0.53 | 3548 | 47.74 | 0.75 | 7193 | 31.56 | 0.25 | 14665 | |

0.1 | 121.56 | 2.21 | 955 | 74.79 | 1.01 | 1865 | 48.23 | 0.76 | 3714 | 31.96 | 0.31 | 7626 | |

Baboon | 1.0 | 379.10 | 3.7 | 8089 | 238.87 | 1.6 | 15768 | 153.01 | 0.8 | 32843 | 98.05 | 0.4 | 65011 |

0.5 | 381.48 | 4.2 | 4102 | 239.03 | 1.8 | 7966 | 153.69 | 1.2 | 16734 | 98.55 | 0.5 | 31460 | |

0.2 | 379.65 | 3.0 | 1688 | 239.69 | 1.6 | 3310 | 154.03 | 0.8 | 6722 | 99.41 | 0.5 | 12806 | |

0.1 | 382.09 | 3.7 | 892 | 240.77 | 1.2 | 1721 | 154.77 | 0.7 | 3500 | 100.58 | 0.6 | 6586 | |

Peppers | 1.0 | 233.98 | 2.3 | 7962 | 140.55 | 3.6 | 14767 | 87.20 | 3.4 | 29386 | 55.60 | 0.5 | 58755 |

0.5 | 235.59 | 3.6 | 4026 | 141.83 | 3.7 | 7518 | 87.10 | 2.9 | 15149 | 55.89 | 0.6 | 30413 | |

0.2 | 236.74 | 5.2 | 1678 | 141.25 | 4.3 | 3109 | 89.21 | 4.2 | 6069 | 56.56 | 0.6 | 12313 | |

0.1 | 234.86 | 2.5 | 884 | 143.66 | 3.2 | 1635 | 88.45 | 3.3 | 3221 | 57.24 | 0.7 | 6323 | |

Lake | 1.0 | 205.86 | 1.8 | 8147 | 133.61 | 1.4 | 14749 | 88.14 | 1.0 | 29328 | 57.95 | 0.8 | 57507 |

0.5 | 205.92 | 1.6 | 4181 | 133.94 | 1.4 | 7430 | 88.51 | 1.1 | 14856 | 58.45 | 0.8 | 28967 | |

0.2 | 206.64 | 1.9 | 1716 | 136.19 | 3.0 | 3075 | 89.40 | 1.1 | 6165 | 59.16 | 0.8 | 11931 | |

0.1 | 206.91 | 2.2 | 892 | 136.00 | 3.0 | 1580 | 89.37 | 1.1 | 3105 | 60.16 | 1.0 | 6257 | |

Airplane | 1.0 | 112.42 | 14.8 | 7755 | 59.76 | 8.1 | 15400 | 37.55 | 2.4 | 29939 | 23.39 | 1.2 | 60463 |

0.5 | 105.41 | 12.2 | 3885 | 60.55 | 7.1 | 7769 | 35.88 | 1.5 | 15081 | 23.21 | 1.0 | 30198 | |

0.2 | 123.11 | 14.0 | 1672 | 58.61 | 4.4 | 3305 | 34.97 | 2.2 | 6180 | 23.34 | 1.0 | 12669 | |

0.1 | 111.98 | 11.4 | 854 | 57.47 | 5.3 | 1649 | 36.49 | 1.9 | 3146 | 23.36 | 0.8 | 6507 |

© 2020 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Huang, S.-C.
Color Image Quantization Based on the Artificial Bee Colony and Accelerated K-means Algorithms. *Symmetry* **2020**, *12*, 1222.
https://doi.org/10.3390/sym12081222

**AMA Style**

Huang S-C.
Color Image Quantization Based on the Artificial Bee Colony and Accelerated K-means Algorithms. *Symmetry*. 2020; 12(8):1222.
https://doi.org/10.3390/sym12081222

**Chicago/Turabian Style**

Huang, Shu-Chien.
2020. "Color Image Quantization Based on the Artificial Bee Colony and Accelerated K-means Algorithms" *Symmetry* 12, no. 8: 1222.
https://doi.org/10.3390/sym12081222