An Efﬁcient Palette Generation Method for Color Image Quantization

: This article describes an efﬁcient method to generate a color palette for color image quantization. The method consists of two stages. In the ﬁrst stage, the initial palette is generated. Initially, the color palette is an empty set. First, the N colors are generated according to the data distribution of the input image in the RGB (Red, Green, Blue) color space. Then, one color is selected from the N colors and this color is added to the initial palette, and the step is repeated until the color number of the initial palette is equal to K . In the second stage, the quantized image is generated using the fast K-means algorithm. There are many sampling rates used in this study. For each sampled pixel, a fast searching method is employed to efﬁciently determine the closest color in the palette. Experimental results show that the high-quality quantized images can be generated by the proposed method. When the sampling rate equals 0.125, the computation time of the proposed method is less than 0.3 s for all cases.


Introduction
Nowadays, RGB color images are widely used for storage, transmission and display.In order to reduce the storage space required and the transfer time of the color images, several color image quantization techniques have been proposed [1].Color image quantization consists of two procedures.The first is to design a color palette which is a set of representative colors, while the second is to map each image pixel to one color in the color palette.
The key to color image quantization is a good color palette.If a good color palette is used, good reconstructed image quality of the compressed color image can be achieved.Several palette design methods have been proposed for color image quantization.Orchard and Bouman [2] proposed the binary splitting approach for color image quantization.Wu [3] employed an iterative process to divide the color space into boxes based on variance minimization.Then, the average value of each resulting box is represented as a color of the palette.Pei and Lo [4] proposed a color quantization technique which is based on the Kohonen neural network to train the color images.Hsieh and Fan [5] calculated the sorted histogram list, and an adaptive clustering algorithm used this list to extract the palette colors for color image quantization.Omran et al. [6] developed a color image quantization algorithm that combines particle swarm optimization with the K-means clustering algorithm.Ghanbarian et al. [7] proposed the ant colony algorithm for color reduction.Hu and Su [8] employed two test conditions to accelerate the K-means algorithm for color image quantization.Hu et al. [9] proposed two schemes to design the color palette.The first scheme employed the splitting-based technique for initial palette generation, and the second employed the k-means algorithm to generate the final color palette.Celebi [10] introduced fast variants of k-means with several initialization schemes for color image quantization.Celebi et al. [11] introduced an effective color quantization Vector quantization has been successfully used in image compression.There are many techniques which have been proposed to speed up the codebook search in vector quantization [18][19][20][21][22][23][24][25].Wu and Lin [22] proposed a kick-out condition for the fast codeword searching algorithm.In this article, this fast searching method is called by Wu-Lin method.For a color pixel in the color image, the Wu-Lin method can efficiently determine the closest color in the palette.
For the color pixel x = (x 1 , x 2 , x 3 ) in an image and a color y = (y 1 , y 2 , y 3 ) in the palette, the square Euclidean distance is defined as follows: The goal is to find a palette color y such that it minimizes Equation (1).Given the color pixel x, ||x|| 2 is a common term for all palette colors.Therefore, the goal is also to find a palette color y such that it minimizes According to the Cauchy-Schwarz inequality, we have Therefore, the following inequality is always true: If a palette color y satisfies the test condition where SED1_min denotes the minimal SED1 between the color pixel x and the closest palette color y min found so far, then SED1(x, y) ≥ SED1_min can be derived from Equations ( 4) and (5).Therefore, the palette color y is not the closest color.
The color palette is sorted in ascending order of length.Assume that c1 and c2 are two colors in the palette.The following two properties are important.The first property is that if ||c1||< ||x||when the palette color c1 is not the closest color; the palette color c2 is also not the closest color if ||c2||< ||c1||.The second property is that if ||c||> ||x||when the palette color c1 is not the closest color; the palette color c2 is also not the closest color if ||c2||> ||c1||.
If the color pixel x = (125, 65, 130), the value of ||x||is about 191.70. Figure 1a shows the sorted palette of K colors.Assume that the color c is the initial searched palette color for the color pixel x.In this study, the color c is the palette color with the closest length value to x, and the binary search technique is employed to find the color c.In this case, the palette color c = (73, 58, 167).It can be computed that the value of ||c||is about 191.26.Therefore, Figure 1b shows the searching order of colors in the palette.where SED1_min denotes the minimal SED1 between the color pixel x and the closest palette color ymin found so far, then 1(, ) ≥ 1_ can be derived from Equations ( 4) and (5).Therefore, the palette color y is not the closest color.
The color palette is sorted in ascending order of length.Assume that c1 and c2 are two colors in the palette.The following two properties are important.The first property is that if ||c1|| < ||x|| when the palette color c1 is not the closest color; the palette color c2 is also not the closest color if ||c2|| < ||c1||.The second property is that if ||c|| > ||x|| when the palette color c1 is not the closest color; the palette color c2 is also not the closest color if ||c2|| > ||c1||.
If the color pixel x = (125, 65, 130), the value of ||x|| is about 191.70. Figure 1a shows the sorted palette of K colors.Assume that the color c is the initial searched palette color for the color pixel x.In this study, the color c is the palette color with the closest length value to x, and the binary search technique is employed to find the color c.In this case, the palette color c = (73, 58, 167).It can be computed that the value of ||c|| is about 191.26.Therefore, Figure 1b shows the searching order of colors in the palette.

The Proposed Method
The method consists of two stages: initial palette generation and fast K-means algorithm.

Initial Palette Generation
For the color pixel x = (x1, x2, x3) in an image, x1, x2, and x3 are integers between 0 and 255. Figure 2 shows the data distribution of the Airplane image in the RGB color space.The color pixel x = (x1, x2, x3) in the Airplane image corresponds to a point (x1, x2, x3) in Figure 2. The 3D RGB space can be divided into non-overlapping cubes.In this study, each cube size is 16 × 16 × 16 such that there are 4096 cubes in total.These cubes are identified as Cube(i), i = 0, 1, …, 4095.For the initial palette generation, the proposed method only considers the cubes in which the point number contained in them is greater than or

The Proposed Method
The method consists of two stages: initial palette generation and fast K-means algorithm.

Initial Palette Generation
For the color pixel x = (x 1 , x 2 , x 3 ) in an image, x 1 , x 2 , and x 3 are integers between 0 and 255. Figure 2 shows the data distribution of the Airplane image in the RGB color space.The color pixel x = (x 1 , x 2 , x 3 ) in the Airplane image corresponds to a point (x 1 , x 2 , x 3 ) in Figure 2. The 3D RGB space can be divided into non-overlapping cubes.In this study, each cube size is 16 × 16 × 16 such that there are 4096 cubes in total.These cubes are identified as Cube(i), i = 0, 1, . . ., 4095.For the initial palette generation, the proposed method only considers the cubes in which the point number contained in them is greater than or equal to Thr.These considered cubes are identified as mCube(i), i = 0, 1, . . ., N−1.The point number contained in mCube(i) and the center of all the points in mCube(i) are denoted by initn(i) and initc(i), respectively.For example, the point number contained in mCube(0) is equal to 3. Assume that the locations of these points are (81, 115, 35), (85, 118, 40) and (90, 116, 36).Hence, initc(0) =    After the N colors initc(i), i = 0, 1, …, N-1, are determined, the proposed method selects K colors from the N colors to generate the initial palette.The steps of initial palette generation are as follows.After the N colors initc(i), i = 0, 1, …, N-1, are determined, the proposed method selects K colors from the N colors to generate the initial palette.The steps of initial palette generation are as follows.After the N colors initc(i), i = 0, 1, . . ., N−1, are determined, the proposed method selects K colors from the N colors to generate the initial palette.The steps of initial palette generation are as follows.
Step 1: The initial palette is an empty set.
Step 3: For the colors initc(i) with Selected(i) = 0, compute the square Euclidean distance between the color initc(i) and each color in the initial palette.The minimum value among these square Euclidean distances is identified as Dist(i).For the color initc(i), the value DistN(i) is computed as follows If DistN(j) == max {DistN(i) | if Selected(i) == 0, i = 0, 1, . . ., N−1}, then the color initc(j) is selected and added to the initial palette.
Step 4: If K > Cno, then go to Step 3. Otherwise go to Step 5.
Step 5: The initial palette is generated.

Fast K-Means Algorithm
The K-means algorithm is the common data clustering method.However, the K-means algorithm is time consuming.In order to reduce the computational cost, the fast K-means algorithm is developed.
The data sampling process is employed, and many sampling rates are used in this study.The sampling rate = 1 indicates that every pixel of the color image is sampled.For the 2 × 2 block shown in Figure 4a, only one pixel is sampled from the 2 × 2 block if the sampling rate = 0.25.In this study, a random number, denoted by rnum1, is generated.If the value of (rnum1% 4) is equal to 3, then the location of the sampled pixel is (3/2, 3% 2) = (1, 1).For the 4×4 block shown in Figure 4b, two pixels are sampled from the 4 × 4 block if the sampling rate = 0.125.In this study, a random number, denoted by rnum2, is generated.If the value of (rnum2% 8) is equal to 5, then the location of the first sampled pixel is (x1, y1) = (5/4, 5% 4) = (1, 1) and the location of the second sampled pixel is (x2, y2) = (x1 + 2, (y1 + 2)% 4) = (3,3).that the color initc(i) has been selected and added to the initial palette.Cno = 0.
Step 3: For the colors initc(i) with Selected(i) = 0, compute the square Euclidean distance between the color initc(i) and each color in the initial palette.The minimum value among these square Euclidean distances is identified as Dist(i).For the color initc(i), the value DistN(i) is computed as follows If DistN(j) == max {DistN(i) | if Selected(i) == 0, i = 0, 1, …, N-1}, then the color initc(j) is selected and added to the initial palette.
Step 4: If K > Cno, then go to Step 3. Otherwise go to Step 5.
Step 5: The initial palette is generated.

Fast K-Means Algorithm
The K-means algorithm is the common data clustering method.However, the Kmeans algorithm is time consuming.In order to reduce the computational cost, the fast Kmeans algorithm is developed.
The data sampling process is employed, and many sampling rates are used in this study.The sampling rate = 1 indicates that every pixel of the color image is sampled.For the 2 × 2 block shown in Figure 4a, only one pixel is sampled from the 2 × 2 block if the sampling rate = 0.25.In this study, a random number, denoted by rnum1, is generated.If the value of (rnum1% 4) is equal to 3, then the location of the sampled pixel is (3/2, 3% 2) = (1, 1).For the 4×4 block shown in Figure 4b According to the data sampling process described above, the sampling rates 0.5, 0.0625 and 0.03125 can also be used.Two pixels are sampled from the 2 × 2 block if the According to the data sampling process described above, the sampling rates 0.5, 0.0625 and 0.03125 can also be used.Two pixels are sampled from the 2 × 2 block if the sampling rate = 0.5, only one pixel is sampled from the 4 × 4 block if the sampling rate = 0.0625, and two pixels are sampled from the 8 × 8 block if the sampling rate = 0.03125.
The steps of the fast K-means algorithm can be described as follows.
Input: The initial palette described in Section 3.1.
Step 1: The data sampling process is employed.The sampled color pixels are denoted by SCP i , i = 0, 1, . . ., SPN-1.Iter = 0 StopF = 0 Step 2: For the sampled pixel SCP i , the closest color in the palette is denoted by CCP i .The color CCP i is efficiently determined by the Wu-Lin method described in Section 2. If the index value of its closest palette color is r, then the sampled pixel is classified into the r-th group.
Step 3: Compute the mean values of these K groups.The new color palette is generated by sorting these K values in ascending order of length.
Step 6: The color palette is generated.The required iteration number, denoted by Iter, is output.

Experimental Results and Discussion
The proposed algorithm is implemented in C language.All of the experiments were performed on a PC running under the operating system of Windows 7, with an I7 processor (3.6 GHz) and 32 GBytes of RAM.The set of test images includes Lena, Baboon, Lake, Peppers and Airplane, which have the same size of 512 × 512 pixels.They were downloaded from [26] and were used for conducting the experiments.The parameters Thr = 10 and Max_cycle = 20 were used in the experiments.
The experimental results are shown in Table 1.The results presented are the solutions with the mean square error, the required iteration number, and computation time.The mean square error (MSE) is defined as follows: where f is the original color image, and f is the quantized image.For the same image and same color palette size, we can observe the following: (1) The mean square errors obtained when the sampling rate = 1, 0.5, 0.25 and 0.125 are near, and the mean square error obtained when the sampling rate = 0.03125 is higher than that obtained when the sampling rate = 1, 0.5, 0.25, 0.125 and 0.0625 in most cases.(2) When the sampling rate decreases, the computation time decreases in most cases.
Table 2 shows the computation time (milliseconds) of the proposed method with a sampling rate of 0.125.The total computation time is the summation of T1 and T2.T1 is the computation time for initial palette generation and T2 is the computation time for clustering by the fast K-means algorithm.It is observed that the value of T1 is between 10 and 30 milliseconds, the value of T2 is between 20 and 200 milliseconds, and the total computation is between 30 and 230 milliseconds.For the Lena image, the required iteration numbers are 18 and 13 for K = 128 and 256, respectively.Therefore, the results show that the total computation time when K = 256 is less than the total computation time when K = 128.
Figures 5-9 illustrate the quantized images of Lena, Baboon, Lake, Peppers, and Airplane, respectively.The color numbers of the palette range from 32 to 256.These quantized images are produced by the proposed method with a sampling rate of 0.125.It shows that as the color number of the palette increases, the quality of the quantized image produced by the proposed method always improves.It is noted that the visual quality of the 256 colors quantized image is approximately the same as that of the original image.(a) (d) (e) (a) In addition, two color images, Splash and Tree, were used for testing.The S image consists of 51 2× 512 pixels, and the Tree image consists of 256 × 256 pixels.Fig 10 and 11 illustrate the quantized images of Splash and Tree, respectively.These q tized images are produced by the proposed method with a sampling rate of 0.125 results show that the proposed method can generate high-quality quantized images observed that the visual quality of the 256 colors quantized image is approximatel same as that of the original image.In addition, two color images, Splash and Tree, were used for testing.The Splash image consists of 512 × 512 pixels, and the Tree image consists of 256 × 256 pixels.Figures 10 and 11 illustrate the quantized images of Splash and Tree, respectively.These quantized images are produced by the proposed method with a sampling rate of 0.125.The results show that the proposed method can generate high-quality quantized images.It is observed that the visual quality of the 256 colors quantized image is approximately the same as that of the original image.
In addition, two color images, Splash and Tree, were used for testing.The S image consists of 51 2× 512 pixels, and the Tree image consists of 256 × 256 pixels.Fi 10 and 11 illustrate the quantized images of Splash and Tree, respectively.These q tized images are produced by the proposed method with a sampling rate of 0.125 results show that the proposed method can generate high-quality quantized images observed that the visual quality of the 256 colors quantized image is approximatel same as that of the original image.The effect of the parameter Thr on the solution is discussed in this section.parison is applied to the Baboon and Peppers images.The MSE obtained will be a figure for comparison.The proposed method only considers the cubes for which the point number contained in them is greater than or equal to Thr in order to generate the initial palette.Figure 12 compares the results of Thr = {3, 10, 30, 60} for the Baboon image.This figure shows that the mean square errors obtained when Thr = 3, 10 and 30 are near, and the average mean square error obtained when Thr = 60 is slightly higher than that obtained when Thr = 3, 10 and 30. Figure 13 compares the results of Thr = {3, 10, 30, 60} for the Peppers image.This figure shows that the average mean square error obtained when Thr = 10 is slightly lower than that obtained when Thr = 3 and 30, and the average mean square error obtained when Thr = 60 is higher than that obtained when Thr = 3, 10 and 30.Therefore, the value selected for the parameter Thr of the proposed algorithm was 10.
square error obtained when Thr = 60 is slightly higher than that obtained when Thr = 3 and 30. Figure 13 compares the results of Thr = {3, 10, 30, 60} for the Peppers image.T figure shows that the average mean square error obtained when Thr = 10 is slightly low than that obtained when Thr = 3 and 30, and the average mean square error obtained wh Thr = 60 is higher than that obtained when Thr = 3, 10 and 30.Therefore, the value selec for the parameter Thr of the proposed algorithm was 10.In 2020, a color image quantization algorithm, identified as PSO+ATCQ-3, that co bines particle swarm optimization and artificial ants was proposed by Pérez-Delgado [1 The quality of the quantized images produced by PSO+ATCQ-3 is better than that p duced by some well-known color image quantization methods.The PSO+ATCQ-3 al rithm was implemented in C language and executed on a PC running under the Lin The proposed method only considers the cubes for which the point number contained in them is greater than or equal to Thr in order to generate the initial palette.Figure 12 compares the results of Thr = {3, 10, 30, 60} for the Baboon image.This figure shows that the mean square errors obtained when Thr = 3, 10 and 30 are near, and the average mean square error obtained when Thr = 60 is slightly higher than that obtained when Thr = 3, 10 and 30. Figure 13 compares the results of Thr = {3, 10, 30, 60} for the Peppers image.This figure shows that the average mean square error obtained when Thr = 10 is slightly lower than that obtained when Thr = 3 and 30, and the average mean square error obtained when Thr = 60 is higher than that obtained when Thr = 3, 10 and 30.Therefore, the value selected for the parameter Thr of the proposed algorithm was 10.In 2020, a color image quantization algorithm, identified as PSO+ATCQ-3, that combines particle swarm optimization and artificial ants was proposed by Pérez-Delgado [17].The quality of the quantized images produced by PSO+ATCQ-3 is better than that produced by some well-known color image quantization methods.The PSO+ATCQ-3 algorithm was implemented in C language and executed on a PC running under the Linux In 2020, a color image quantization algorithm, identified as PSO+ATCQ-3, that combines particle swarm optimization and artificial ants was proposed by Pérez-Delgado [17].The quality of the quantized images produced by PSO+ATCQ-3 is better than that produced by some well-known color image quantization methods.The PSO+ATCQ-3 algorithm was implemented in C language and executed on a PC running under the Linux operating system with an I7 processor (2 GHz) and 16 GBytes of RAM [17].The experimental results obtained by PSO+ATCQ-3 are shown in Table 3.
First, the performance of the proposed method with sampling rate = 0.125 is compared to the iteration 1 of PSO+ATCQ-3.The MSE obtained by PSO+ATCQ-3 is higher than that obtained by the proposed method for all cases.The computation time of PSO+ATCQ-3 is between 468 and 2074 milliseconds.The computation time of the proposed method is

Figure 1 .
Figure 1.(a) The color palette is sorted in ascending order of length, (b) the searching order of colors in the palette if the color pixel x = (125, 65, 130).

Figure 1 .
Figure 1.(a) The color palette is sorted in ascending order of length, (b) the searching order of colors in the palette if the color pixel x = (125, 65, 130).

Figure 2 .
Figure 2. Data distribution of the Airplane image in the RGB (Red, Green, Blue) color space.

Figure 2 .
Figure 2. Data distribution of the Airplane image in the RGB (Red, Green, Blue) color space.

Figure 2 .
Figure 2. Data distribution of the Airplane image in the RGB (Red, Green, Blue) color space.

Figure 4 .
Figure 4. (a) Only one pixel is sampled, (b) two pixels are sampled

Figure 4 .
Figure 4. (a) Only one pixel is sampled, (b) two pixels are sampled

Figure 11 .
Figure 11.(a) The Tree image, (b) 32 colors with MSE = 34.50,(c) 64 colors with MSE = 20.92,(d) 128 colors with MSE = 13.79,(e) 256 colors with MSE = 9.44.The effect of the parameter Thr on the solution is discussed in this section.The comparison is applied to the Baboon and Peppers images.The MSE obtained will be shown in a figure for comparison.The proposed method only considers the cubes for which the point number contained in them is greater than or equal to Thr in order to generate the initial palette.Figure12compares the results of Thr = {3, 10, 30, 60} for the Baboon image.This figure shows that the mean square errors obtained when Thr = 3, 10 and 30 are near, and the average mean square error obtained when Thr = 60 is slightly higher than that obtained when Thr = 3, 10 and 30.Figure13compares the results of Thr = {3, 10, 30, 60} for the Peppers image.This figure shows that the average mean square error obtained when Thr = 10 is slightly lower than that obtained when Thr = 3 and 30, and the average mean square error obtained when Thr = 60 is higher than that obtained when Thr = 3, 10 and 30.Therefore, the value selected for the parameter Thr of the proposed algorithm was 10.

Table 2 .
The computation time (milliseconds) of the proposed method with a sampling rate of 0.125.