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

: Color image quantization techniques have been widely used as an important approach in color image processing and data compression. The key to color image quantization is a good color palette. A new method for color image quantization is proposed in this study. The method consists of three stages. The first stage is to generate N colors based on 3D histogram computation, the second is to obtain the initial palette by selecting K colors from the N colors based on an artificial bee colony algorithm, and the third is to obtain the quantized images using the accelerated K ‐ means algorithm. In order to reduce the computation time, the sampling process is employed. The closest color in the palette for each sampled color pixel in the color image is efficiently determined by the mean ‐ distance ‐ ordered partial codebook search algorithm. The experimental results show that the proposed method can generate high ‐ quality quantized images with less time consumption.


Introduction
Color image quantization is one of the digital image processing techniques [1]. Color image quantization consists of two steps. The first step is to generate a set of representative colors in order to obtain a color palette. The second is to map each pixel in the color image to one color in the color palette. The main purpose of color image quantization is to reduce the storage requirements and the transfer time of the image.
Hsieh and Fan [2] proposed a method for color image quantization based on an adaptive clustering algorithm and a pixel-mapping algorithm. Omran et al. [3] developed a color image quantization algorithm based on particle swarm optimization and the K-means algorithm. The main disadvantage of their method is the high computational cost. Hu and Lee [4] introduced the use of stable flags for palette entries in order to accelerate the K-means algorithm for palette design. Celebi [5] implemented the fast and exact variants of K-means with several initialization schemes. Su and Hu [6] proposed a color image color quantization algorithm based on self-adaptive differential evolution. El-Said [7] proposed a fuzzy clustering algorithm, which combines the artificial fish swarm algorithm and an efficient extension of fuzzy c-means (FCM), for color image quantization. Schaefer and Nolle [8] introduced a new approach to color image quantization. In their method, the color palette is derived by the simulated annealing algorithm in order to provide good image quality according to S-CIELAB. In 2015, a color quantization method, called ATCQ, was proposed by Pérez-Delgado [9]. ATCQ adapted some of the features of the basic Ant-tree to obtain a quicker algorithm for color image quantization. Ueda et al. [10] described a modification of the median cut algorithm. In their method, a combination of linear discriminant analysis and principal analysis was used to accomplish effective partitioning of the color space. In 2019, application of the shuffled-frog leaping algorithm to perform color image quantization was proposed by Pérez-Delgado [11]. Each frog represented a quantized palette and the objective function considered is the mean square error.
Although some existing methods can obtain high-quality quantized images, these methods suffer from the drawback of high computational cost. In order to obtain the quantized images with high image quality and low computational cost, a color image quantization technique is proposed in this study. Experimental results show that the proposed method can generate high-quality quantized images with less time consumption.
The rest of this paper is organized as follows. In Section 2, some related works are reviewed. In Section 3, the color image quantization method is described. In Section 4, some experimental results are presented. Finally, some conclusions are given in Section 5.

Related Works
In this section, the artificial bee colony algorithm and the mean-distance-ordered partial codebook search algorithm will be reviewed.

Artificial Bee Colony (ABC) Algorithm
The artificial bee colony algorithm [12][13][14][15][16][17][18][19][20][21][22] was first proposed by Karaboga and was inspired by the foraging behaviors of bee colonies. In this study, the number of food sources is denoted by SN, and the position of a food source represents a possible solution to the optimization problem. Each solution si (i = 0, 1, 2, …, SN − 1) is a K-dimensional vector. Here, K is the color number of a color palette.
In the employed bee phase, a new solution vi is produced by the i-th employed bee as follows: where st is a food source selected randomly, j is selected from the set {0, 1, 2, …, K − 1}, and ij  is a random number within the range [−1, 1]. In the onlooker bee phase, each onlooker bee selects a food source depending on probi which is calculated by the following expression:  (2) where fitness(si) is the fitness value of the solution si. Then, the onlooker bees try to improve the solutions by using Equation (1).
The main steps of the ABC algorithm are shown as follows: Algorithm 1: ABC algorithm [12] Step 1: Generate the initial population si, i = 0, 1, 2, …, SN − 1 triali = 0, i = 0, 1, 2, …, SN − 1. In the ABC algorithm, trial is a vector holding trial numbers through which solutions cannot be improved Set cycle to 1 Step 2: Evaluate the fitness fitness(si) of the population and memorize the best solution so far Repeat Step 3: Employed bee phase Step 4: Compute the values probi (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

Mean-Distance-Ordered Partial Codebook Search (MPS) Algorithm
The MPS algorithm is a fast search algorithm for vector quantization [23,24]. Here, the MPS algorithm is employed to achieve reduction in computation time for color image quantization. For each color pixel in the color image, the closest color in the palette can be efficiently determined by the MPS algorithm.
For the color pixel x and the palette color c in the palette, the squared Euclidean distance (SED) and the squared sum distance (SSD) are defined as follows.
The following inequality that holds true for the color pixel x and the palette color c is described as follows [23]: In the MPS algorithm, the test condition was employed to reject some impossible palette colors: where dmin denotes the minimal SED between the color pixel x and the closest color cmin found so far. The inequality dmin < SED(x,c) can be derived from Equations (5) and (6), and thus the palette color c cannot be the closest color.
If the color pixel x = (100, 50, 80), the sorted palette of K colors is as depicted in Figure 1a. In this study, the initial searched palette color for the color pixel x is the palette color with the closest mean value to x. The initial searched palette color can be found by the binary search technique. In this case, the palette color with the closest mean value to x is (101, 52, 78); therefore, the searching order of colors in the palette is depicted in Figure 1b.
It is noted that the MPS test condition has two properties. Here, mean (c), mean (c1), and mean (x) denote the mean value of palette color c, the mean value of palette color c1, and the mean value of color pixel x, respectively. The first property is that if mean (c) is less than mean (x), when the palette color c is rejected, the palette color c1 is also rejected if mean (c1) is less than mean (c). The second property is that if mean (c) is greater than mean (x), when the palette color c is rejected, the palette color c1 is also rejected if mean (c1) is greater than mean (c).

Proposed Color Image Quantization Algorithm
The method consists of three stages. The system flowchart is shown in Figure 2. The three stages are described in this section.

Generate N Initial Colors
The RGB color system is adopted in this study. The R, G and B values range from 0 to 255. For the Lake image, Figure 3 shows its 3D histogram. The RGB values of each pixel in an image correspond to a point of its 3D histogram. In the proposed scheme, the 3D RGB space is divided into non-overlapping cubes, and the size of each cube is 16 × 16 × 16. There are (256 × 256 × 256)/(16 × 16 × 16) = 4096 cubes in total. It is observed that many cubes contain no point. If the point number contained in the cube is equal to or larger than the threshold PixelThr, then the cube will be preserved. Assume that the number of the preserved cube is N. The point number contained in the i-th preserved cube is denoted by initialn

Select K Colors by an ABC Algorithm
In this study, an ABC algorithm is employed to select K colors from the N initial colors to form the initial palette. The basic components of the artificial bee colony algorithm for solving this problem are described in the following subsections.

Representation of Solutions and Fitness Function
The proposed method considers the N initial colors and their corresponding point numbers in order to generate the initial palette. In the initialization phase, the SN solution si where

Generation of a New Solution vi
As described in Section 2.1, the structure of the original ABC is suitable for continuous problems. Thus, Equation (1) needs to be modified for this specific problem. Let si = (si,0, si,1, si,2, …, si,K−1) be the present solution, while st = (st,0, st,1, st,2, …,st,K−1) is the randomly selected solution. The proposed method will generate the new solution vi. The new solution vi is the same as si except that si,j is replaced by vi,j, where j is selected from the set {0, 1, 2,…, K − 1}.
The value of vi,j is computed by the following steps: The steps of computing the value of v i,j Step 1: In the employed bee phase, the i-th employed bee produces a new solution vi by the method described in Section 3.2.2. If fitness(vi) > fitness(si) then si is replaced by vi and triali is set to 0 else triali = triali + 1. In the onlooker bee phase, each onlooker bee which selects a solution si depending on probi also produces a new solution vi by the method described in Section 3.2.2. If fitness(vi) > fitness(si) then si is replaced by vi and triali is set to 0 else triali = triali+1. In the scout bee phase, the scout bee randomly produces the new solution to replace si if the triali of solution si 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.
In the second stage, the criterion N K must be satisfied. If the value of N obtained is less than the value of K, the proposed method will decrease the value of PixelThr in order to satisfy the criterion N K. When the value of PixelThr is set to 1 and the value of N obtained is less than the value of K, the proposed method will skip the second stage and set K = N. That is, the color number of a color palette is N.

Accelerated K-Means Algorithm
The K-means algorithm is the most commonly used algorithm for data clustering. It is found that the computational cost of the K-means algorithm for color image quantization is very high. Hence, the accelerated K-means algorithm is employed for color image quantization in this study.
In order to achieve reduction in computation time, the sampling process is employed in this study. First, the color image is divided into many non-overlapping blocks. When every pixel of the color image is sampled it indicates that the sampling rate = 1, when only one pixel is sampled for a 2 × 2 block it indicates that the sampling rate = 0.25, when only two pixels are sampled for a 4 × 4 block it indicates that the sampling rate = 0.125, and when only one pixel is sampled for a 4 × 4 block it indicates that the sampling rate = 0.0625. Then, the sampled pixels and the initial palette serve as the input of the accelerated K-means algorithm. Detailed descriptions of the accelerated K-means algorithm for color image quantization are given below.

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.

Experimental Results
The proposed algorithm was implemented in C language and executed on a PC running under the operating system of Windows 7 with Intel Core 3.6 GHz CPU and 32 GBytes of RAM. The five color images Lena, Baboon, Lake, Peppers and Airplane with a size of 512 × 512 were used for conducting the experiments. The following parameters were used in the experiments: PixelThr = 30, SN = 20, ABC_cycle = 15 and K_means_cycle = 20.
In the experiments, the proposed algorithm was executed 20 times for each given image. Table 1 where f is the original color image, and f' is the quantized image. It was observed that when K increased, the average mean square error decreased and the average computation time increased. When the sampling rate increased, the average computation time increased for all cases, and the average mean square error decreased in most cases. In the proposed method, the total computation time was the summation of computation time for initial palette generation and computation time for clustering by the accelerated K-means algorithm. Table 2 shows the computation time for color image quantization. These results were obtained by the proposed method with a sampling rate of 0.125. It was observed that the computation time for initial palette generation always increased with the increase in K. Similarly, the computation time for clustering by accelerated K-means algorithm always increased with the increase in K.  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 Figures 5-9 illustrate the quantized images of Lena, Baboon, Lake, Peppers, and Airplane, respectively, corresponding to K = 32, 64, 128 and 256. These figures were obtained by the proposed method with a sampling rate of 0.125. It shows that the proposed method can generate high-quality quantized images. We can observe that there is no visual difference between the original and the 256 colors quantized images. In Figure 8a, there is a red tree in the middle region. However, the color of this tree is not red in Figure 8b. That is, there are some visual differences between the original and the 32 colors quantized images.

The Effect of the Algorithm Parameters
This subsection analyzes the effect of the algorithm parameters on the solution. The comparison was applied to the Lena image quantized to 32 and 256 colors. The following parameters were used in the experiments: PixelThr = 30, SN = 20, ABC_cycle = 15 and K_means_cycle = 20. When a parameter was analyzed, the other parameters remained unchanged, and the average MSE and the average computation time (milliseconds) obtained will be shown in a figure for comparison.
As described in Section 3.1, the 3D RGB space was divided into non-overlapping cubes, and the size of each cube was 16 × 16 × 16. If the point number contained in the cube was equal to or larger than the threshold PixelThr, then the cube was preserved. The number of the preserved cube was N in this study. Figure 10 compares the results of PixelThr = {5, 15, 30}. This figure shows that as PixelThr increased, the computation time decreased slightly for all cases. When PixelThr increased, the MSE value decreased slightly in most cases.
SN is the number of food sources in the ABC algorithm. The ABC algorithm was employed to select K colors from the N initial colors to form the initial palette in this study. Figure 11 compares the results of SN = {10, 20, 30}. This figure shows that as SN increased, the computation time increased slightly for all cases. It was observed that the MSE value does not always decrease with the increase in SN.
The ABC algorithm was finished if the criterion cycle > ABC_cycle was satisfied. Figure 12 compares the results of ABC_cycle = {5, 15, 30}. This figure shows that as ABC_cycle increased, the computation time increased slightly for all cases. It was observed that the MSE value does not always decrease with the increase in ABC_cycle.
In the accelerated K-means algorithm, the algorithm stops if the criterion cycle > K_means_cycle is satisfied. Figure 13

Comparison with the Method Proposed by Pérez-Delgado
In 2019, the application of the shuffled-frog leaping algorithm to perform color quantization was proposed by Pérez-Delgado [11], and this method is identified as SFLA-CQ. The SFLA-CQ algorithm was coded in C language and executed on a PC running under the Linux operating system with 8 GBytes of RAM and an AMD Ryzen 7 1800X Turbo processor (4.0 GHz). Table 3 shows the results obtained by SFLA-CQ.
The performance of the proposed method with sampling rate = 0.125 was compared to SFLA-CQ with sampling rate = 0.1. For the Lena image, the average MSE obtained by the proposed method was near to that obtained by SFLA-CQ. For the Baboon image, the average MSE obtained by the proposed method was slightly higher than that obtained by SFLA-CQ. For the Pepper and Lake images, the average MSE obtained by the proposed method was slightly lower than that obtained by SFLA-CQ when K = 64, 128 and 256. For the Airplane image, the average MSE obtained by the proposed method was lower than that obtained by SFLA-CQ. These results clearly show that the computation time of SFLA-CQ is greater than that of the proposed method.
In summary, the proposed method can generate high-quality quantized images. These results reveal that the proposed method is superior to SFLA-CQ in terms of average computation time.

Conclusions
A new method is presented for color image quantization in this study. The method consists of three stages. The first stage is to generate N colors based on 3D histogram computation, the second is to obtain the initial palette by selecting K colors from the N colors based on an ABC algorithm, and the third is to obtain the quantized images using the accelerated K-means algorithm. In order to achieve reduction in computation time, the sampling process and the MPS algorithm are employed in this study.
Experimental results show that the proposed method can generate high-quality quantized images. When the sampling rate = 0.125, the average computation time of the proposed method is less than 1 s for all cases. The main contributions of this paper are that the proposed method can generate high-quality quantized images with less time consumption, and the experimental results reveal the feasibility of the proposed approach.
Funding: This research received no external funding.