Você está na página 1de 10

A Fast Palette Searching Algorithm for Color Quantization

Xin Zhang1, Jun Zhang1, Hui Wang1


1

Multimedia Research & Development Center, National Univ. of Defense Tech., Changsha, Hunan Province, 410073, P.R.C

ijunzhang@hotmail.com

Abstract. An Equal-Norm Equal-Sum Palette Searching (ENESPS) algorithm is proposed to speed up the color mapping step in color quantization. This algorithm sorts the palette colors by their norms first. Then, the palette color, whose norm is closest to that of the pixel color to be mapped, is chosen as the initial searching point. Afterward, the Norm Constraint and the Sum Constraint are applied to limit the searching range. Experimental results show that ENESPS algorithm can obtain shorter Averaged Searching Length in comparison with other methods and it can reduce the computation time of color quantization remarkably. Keywords: color quantization; vector quantization; color mapping; Equal-Norm Equal-Sum Palette Searching; Averaged Searching Length

Introduction

True color images always contain huge amount of 3D color vectors, which not only increases the resources needed to display or transmit them, but also brings great difficulty to their processing and analyzing. An effective approach to circumvent these problems is to convert true color images to indexed ones with at most hundreds of palette colors. Obviously, distortions caused by the conversion must be visually acceptable. This process is just the color quantization of digital images. Generally, it is defined as the process of reducing the number of colors in a digital image by replacing them with the closest representative colors [1], [2]. Heckbert explored the problem of color quantization firstly in earlier 1980s [3]. After that, many different color quantization methods are presented. These methods can be grouped into two categories: the splitting and the clustering. Readers may refer to [4-6] for a comprehensive review of existed color quantization methods. As we can find, though these methods differ more or less from each other, they consist of two common steps [4]. The first step is palette configuration, in which specified number of colors is selected to form a palette. The second step is color mapping, in which each pixels color is assigned to the closest palette one. The latter is far more complex than the former step. This can be elaborated as follows. According to psycho-visual principles, Euclidean distance between color vectors can be employed to measure the visual difference between corresponding colors [7], which means that the most similar color is just the nearest one (in some color space).

Therefore, color mapping is just to search in the palette, select the most nearest one, and assign it to each pixel color in the input image. This is the so-called nearest neighbor rule. Besides, Squared Euclidean Distance (SED) is always adopted instead of the naive Euclidean distance to avoid the time-consuming rooting operation needed by the latter. Formally, let I be a 24-bit true color image, K be the quantization level1 P P pre-specified, P = {c1P , c2 ,..., cK } be the current palette. The SED between an arbitrary color vector ci = ( xi1 , xi 2 , xi1 ) in the input image and a palette one c kP = ( xiP , xiP , xiP ) can be formulated as 1 2 3
D(ci , ckP ) = ci ckP
2 P = ( xij xkj )2 j =1 3

(1).

P Color mapping is just to find out the best mapping color c opt P for each ci I , and

map ci to copt . According to the nearest neighbor rule, the best mapping color of ci can be defined as
P copt = arg min{D(ckP , ci )}
P ck

(2)

If full search (FS), i.e. exhaustive search or brute-force search, is exploited to find the best mapping color of each pixel, then the complexity of performing color mapping on image I is O( KN ) , in which N is the total of pixels in I . Moreover, the basic operation in this searching process is summing of squares. This dramatically increases the computational complexity of color mapping, and leads it to be very time-consuming, especially for large input image or high quantization level K . The condition will get even worse for some iterative quantization methods, such as the LBG algorithm [8], because color mapping needs to be performed in each iteration. To sum up, direct use of FS (full search) will make the color mapping step very time-consuming. This severely decreases the applicability of iterative quantization methods, especially when inputting a large image or specifying a high quantization level. Therefore, it is necessary to research on fast palette search methods to speed up the color mapping step, hence accelerate the whole quantization process. Viewing this, the paper proposes the Equal-Norm Equal-Sum Palette Search (ENESPS) algorithm, which makes combinatory use of the norm and sum constraints to narrow the searching range, and shortens the computation time remarkably. The rest part of this paper is organized as follows. Section 2 reviews related works. Section 3 presents the proposed ENESPS algorithm. Then, section 4 displays and analyzes the experimental results. It also gives some concluding remarks.

Related Works

To the authors knowledge, no existed work directly researches on the problem of fast
Quantization level is the number of colors in the palette. It is also the number of colors in the result image after quantization. Generally, it is no more than 255 and far less than the total colors in the input image.
1

palette searching in color mapping. However, since color is always described with three-dimensional vectors, color quantization can be regarded as a special case of vector quantization. Similar problem, i.e. fast codebook searching, exists in vector quantization [9]. And different heuristic approaches to it have been proposed. We can take these approaches as our research basis. The following parts of this section give a brief review of them. Existed fast codebook searching algorithm can be grouped into two classes. The first class makes use of some special codebook structure, such as tree-structure, to implement fast searching. The second class is independent of codebook structure, but introduces some heuristic rules to limit the searching range. The first class of methods requires a pre-processing step to establish the codebook structure. In addition, fixed codebook structure may limit the flexibility of subsequent quantization steps. Viewing this, this paper researches mainly on the second class of fast searching methods, i.e. it tries to introduce some elimination criteria to shorten the palette searching length. At present, there are four elimination criteria commonly used by encoding process in vector quantization. They are partial distortion search (PDS), the Mean Constraint, the Norm Constraint and triangle-inequality-based elimination criterion. Liu gives a detailed introduction to the first three [9]. And Huang et al. discuss about the application of the last one to fast vector encoding [10]. Now, we are to present a brief review on these criteria, in terms of color quantization and in the form of theorems. Since the first criterion is very evident, we will not give its proof.
P Theorem 1 (PDS): Let ci be an input pixel color, c k , clP be two different palette

P colors, i.e. k l . c k can be expanded as c kP = ( x kP1 , x kP2 , x kP3 ) P . If D0 = D(ci , clP ) is known, and there exists some integer M ( 1 M 3 ) satisfying the following P inequality, then c k will not be the best mapping color of ci .

(x
j =1

ij

P xkj ) 2 D0

(3)

P Theorem 2 (the Mean Constraint): Let ci , c k and clP be the same as above. The P averages of vector components of ci and c k are denoted separately as mi and mkP .If

the SED (squared Euclidean distance) between ci and clP , D0 = D(ci , clP ) , is known,
P then only palette color c k satisfying the following condition should be searched.

mi D0 3 < mkP < mi + D0 3

(4)

Proof (Reduction to absurdity). Assuming that (4), then we can get

P ck

does not satisfy inequality


2

mkP mi D0 3 or mkP mi + D0 3 mi mkP

D0 3

Further, since arithmetical average is no more than mean square root,

P P [ ( xij xkj ) 2 ] 3 [ ( xij xkj )] 3 D(ci , ckP ) 3 mi mkP . 2 j =1 j =1

P Combining above two inequalities, we can get D(ci , ckP ) D0 , which means that c k

is surely not the best mapping color of ci . Thus, the theorem is proved.

P Theorem 3 (the Norm Constraint): Let ci , c k and clP be the same as above. The P norms of color vector ci and c k are denoted separately as ci and ckP . If the SED P between ci and clP , D0 = D (ci , clP ) , is known, then only palette color c k satisfying the following condition should be searched.

ci D0 < ckP < ci + D0

(5) does not satisfy inequality

Proof (Reduction to absurdity). Assuming that (5), then we can get

P ck

ckP ci + D0 or ckP ci D0 ( ckP ci ) 2 D0 . In addition, according to the famous Cauchy-Schwarz Inequality, we can get
( ckP ci )2 ckP ci
P D(ci , c k ) = ckP ci
2 2

Combining these inequalities, we can draw the conclusion that


( ckP ci ) 2 D0 ,
P which means that c k is not closer to ci than clP , thus it is surely not the best

mapping color of ci . The theorem is proved.

Theorem 4 (Triangle-Inequality-Based Elimination Criterion): Let ci ,


P ck P and clP be the same as above. The SED between c k and clP is denoted

as D (ckP , clP ) . If the SED between ci and clP , D0 = D (ci , clP ) , is known, then only
P palette color c k satisfying the following condition should be searched.

D(ckP , clP ) < 4 D(ci , clP ) = 4 D0

(6) does not satisfy inequality

Proof (Reduction to absurdity). Assuming that (6), then we can reason out that

P ck

D (ckP , clP ) 4 D (ci , clP ) d (ckP , clP ) 2d (ci , clP ) ,

in which d (ckP , clP ) and d (ci , clP ) separately represent the Euclidean distances between ckP and clP , ci and clP , . Moreover, according to the triangle inequality, we can obtain
d (ckP , clP ) d (ci , ckP ) + d (ci , clP ) .

Based on the combination of above two inequalities, it comes out that


2d (ci , clP ) d (ci , ckP ) + d (ci , clP ) d (ci , clP ) d (ci , ckP )

D(ci , clP ) = D0 D(ci , ckP ) .


P This means that c k is not closer to ci than clP , thus it is surely not the best mapping color of ci . The theorem is proved.

For above four elimination criteria, it is obvious that no equivalence or inclusion relation exists among them. Therefore, they can be combined to obtain even narrower searching ranges. Enlightened by this, several fast codebook searching approaches have been proposed. The EENNS (Equal-average Equal-norm Nearest Neighbor codeword Search) algorithm given in [9] unites the second and third one, i.e. the Mean and Norm Constraint, to accelerate the codebook searching process. Huang et al. researches mainly on how to integrate the fourth one with others, and propose three fast codebook searching algorithms in [10].

The ENESPS Algorithm

Though we describe the four most popular codeword elimination criteria in terms of color quantization above, they are NOT all suitable for color quantization, or rather some of them are not appropriate to be used in color mapping. It is obvious that the PDS criterion is more effective for high dimensional vectors. However, color vector is only three dimensional. Thus, this criterion does not fit for palette searching in color quantization. In addition, the triangle-inequality-based elimination criterion is also not very suitable because it needs to compute the SED between each pair of palette colors beforehand. This requires to perform K ( K 1) 2 additional summing of squares and to save these computational results, which is too expensive, especially for high quantization level K . In conclusion, the Mean and Norm Constraint are much more preferable for color quantization to other criteria. Therefore, we take them as the basis for our proposed ENESPS (Equal-Norm Equal-Sum Palette Searching) algorithm. More accurately speaking, the algorithm is based on the Norm Constraint and the Sum Constraint. The latter is an equivalent of the Mean Constraint.

3.1

The Sum Constraint

A further study on the Mean Constraint is performed first to find out its advantages and disadvantages, which will help us to introduce the Sum Constraint. It is evident that the Mean Constraint described in theorem 2 can effectively narrow the palette searching range. And, compared with the triangle-inequality-based criterion, the additional computation it requires is substantially lighter. But to compute vector component average needs to perform division operation, which is not very

favorable for the inclusion of floating point computation. This is just an important disadvantage of the Mean Constraint. Fortunately, as we know, their is a fixed quantitative relation between the average and sum of a vectors components, and computation of components sum needs no division. Thus we can replace the mean quantity in formula (4) with the sum. This leads to an equivalent criterion, which is more computationally simple. We name it the Sum Constraint.
P Theorem 5 (the Sum Constraint): Let ci , c k and clP be the same as in above P theorems. The sum of components of color vector ci and c k are denoted separately

as si and s k . If the SED between ci and clP , D0 = D (ci , clP ) , is known, then only
P palette color c k satisfying the following inequality should be searched when color mapping. si 3D0 < skP < si + 3D0 (7)

For three dimensional color vectors, the quantitative relation between the sum and the mean of vector components is mi = si 3 , mkP = skP 3 . Substituting ( si 3) and ( s kP 3) for

mi and mkP in formula (4), we can easily

work out the Sum Constraint given in formula (7). As being very simple, the proof process is not to be detailed here. The Sum and Mean constraint are rigidly equivalent. However, the computation of vector component sum requires no division. This can help to reduce the time-consuming floating point operations. When some integer color space, such as RGB, HSV, is adopted, it can even help to avoid floating point operations.

3.2

The ENESPS algorithm

As forementioned, there is no equivalence or inclusion relation exists between the Norm and Sum Constraints. Hence they can be combined together to obtain even narrower searching range, which is the intersection of their respective candidate sets. Theorem 3 and 5 have a common precondition that the pixel color ci to be mapped has been compared with a palette one, clP , and the SED between them is D0 . Thus, to use the Norm and Sum constraints, we must choose an initial searching point clP in the palette and work out D0 first. Moreover, according to formula (5) and (7), it is obvious that the smaller D0 is, the narrower the searching range is limited to. Therefore, the initial searching point should be as near as possible to ci . The EENNS algorithm [9] selects the equal-mean codeword as the initial searching point. However, through comparison experiments, we find that the equal-norm one can lead to even

narrower searching range in most cases. For color quantization, the equal-norm (or equal-mean) codeword is the palette color whose norm (or components average) is closest to that of the pixel color to be mapped. Based on these experiments, we choose the equal-norm palette color as the initial searching point and propose the ENESPS (Equal-Norm Equal-Sum Palette Search) algorithm as follows.
Initialization. Compute the norm and sum of each palette color. Sort palette colors incrementally by their norms. Color Mapping. Scan pixels in the input image sequentially. For each pixel color, execute the following steps. (a). For the current pixel color ci , work out its norm and sum. Search the

sorted palette and find out the palette color clP , whose norm is the closest to that of ci . Then compute their SED, assign it to D0 . (b). Search the sorted palette from the l-th entry, i.e. clP , upward first and then
downward. For each palette color, check whether it satisfies both the Norm and Sum Constraint. If it does, then compute the SED between it and ci . If the resulted SED is smaller than D0 , then update D0 by it, and accordingly modify the upper and lower searching bounds given in formula (5) and (7); otherwise, skip over this palette color. (c). If the norm of currently searched palette color reaches the upper (or lower) searching bound, then terminate searching in this direction. After finishing searching in both directions, map pixel color ci to the best mapping
P color copt found out.

The above algorithm is somewhat similar to the EENNS algorithm proposed by Liu et al. in [9]. However, our algorithm is designed for color quantization, while EENNS is for vector quantization. The fundamental differences between these two algorithms are: The ENESPS algorithm uses the Sum Constraint, while the EENNS algorithm uses the Mean Constraint. As forementioned, the Sum Constraint can help to reduce division operations needed. Moreover, for integer color space, e.g. RGB, ENESPS rounds the rooting results in formula (5) and (7) to integers. This not only cuts down divisions needed, but also thoroughly avoids floating point operations. The equal-norm palette color is chosen as the initial searching point by ENESPS algorithm, while EENNS takes the equal-mean one. Besides, ENESPS searches the palette from the initial point upward first and downward then. As the upper-half has larger volume, performing upward search first is more probable to encounter the best mapping color, hence helps to terminate the palette searching process in advance.

Experimental Results and Conclusions

To verify the proposed ENESPS algorithm, it is implemented with the Microsoft Visual C++ 6.0 and embedded into a color quantization method we proposed in [11], which is based on the famous LBG algorithm and adopts the RGB color space. We perform experiments on six commonly used true color images. They are Baboon, Lena, Peppers, Airplane, House and Sailboat. The computer used in experimentation has a PIV 2.4G CPU and 512M DDR RAM, and the Operating System is Windows 2000 Professional. Two quantitative metrics are adopted to measure the algorithms efficiency. The , first one is ASL averaged searching length which is defined as the averaged palette searching length over each pixel and each LBG iteration. Note that no averaging over iterations is needed when assessing non-iterative quantization methods. Obviously, the smaller the ASL of an algorithm is, the narrower the searching range can be limited to. In other words, efficient heuristic searching method should have smaller ASL. And this metric is independent of the hardware and software environment, in which the experiments are performed. The other metric is the algorithm computation time (in milliseconds), which can give more intuitive impression of the algorithms efficiency. Experimental results on forementioned six images are listed in Table 1 and 2. Their corresponding quantization levels are 128 and 256. The quantization error (measured by Mean Squared Error) and computation time (milliseconds) are also given. For the convenience of comparison, these tables also demonstrate the results of the FS (full search) and EENNS algorithms [9]. These results show that ENESPS can obtain smaller ASL compared with the FS and EENNS algorithms, which means that the proposed ENESPS is the most efficient one. The computation time of each algorithm confirms this conclusion more intuitively. More detailedly, these tables display that EENNS is far less time-consuming than the FS algorithm, and that ENESPS can further obtain a 50% decrease in computation time compared with the EENNS algorithm. This is a great enhancement! We owe the success of the ENESPS algorithm to two aspects: first, it takes the equal-norm palette color as the initial searching point, which shortens the ASL; second, and more importantly, it exploits the Sum Constraint, rounds the rooting results of D0 , so as to avoid the time-consuming floating point operations. Although this rounding sometimes introduces small amount of additional quantization errors, e.g. the MSE of the Airplane and Sailboat images in Table 1 increase by 1, it gains a lot in computation time.

Table 1. The ASL, computation time and MSE of the FS, EENNS, and the proposed ENESPS algorithms at the quantization level of K = 128 . The unit of time is millisecond. Quantization level K=128 Image size Width, Height ASL FS MSE Time ASL EENNS MSE Time ASL ENESPS MSE Time baboon 240,240 128 120 1641 8.9074 120 859 8.3517 120 469 lena 383,384 128 63 3781 5.1522 63 1766 4.7643 63 1016 peppers 381,383 128 100 4156 7.1702 100 2047 6.8004 100 1141 airplane 383,384 128 51 4188 4.8138 51 2203 4.4614 52 1125 house 384,385 128 89 5265 6.8488 89 2203 6.3388 90 1234 sailboat 384,381 128 84 5219 5.7952 84 2281 5.4046 85 1141

Table 2. The ASL, computation time and MSE of the FS, EENNS, and the proposed ENESPS algorithms at the quantization level of K = 256 . The unit of time is millisecond. Quantization level K=256 Image size Width, Height ASL FS MSE Time ASL EENNS MSE Time ASL ENESPS MSE Time baboon 240,240 256 75 3281 13.2322 75 1656 12.0324 75 890 lena 383,384 256 35 5203 8.3829 35 2359 7.4280 35 1218 peppers 381,383 256 62 6203 9.5473 62 2907 8.9812 62 1578 airplane 383,384 256 32 5203 6.7533 32 2703 5.7750 32 1406 house 384,385 256 56 6281 9.7905 56 3047 8.7632 56 1562 sailboat 384,381 256 55 5203 8.7809 55 2938 7.9160 55 1250

References
1. 2. 3. 4. 5. 6. Larabi M.C., Richard N., Fernandez C.: A fast color quantization using a matrix of local pallets. Proc. of Applied Imagery Pattern Recognition Workshop (2000), 136-140 Uysal M., Yarman-Vural F.T.: A Fast Color Quantization Algorithm Using a Set of One Dimensional Color Intervals. Proc. of ICIP98, 1(1998), 191-195 Heckbert, P.: Color image quantization for frame buffer display. ACM Trans. Computer Graphics (SIGGRAPH) 16(3) (1982), 297307 SCHEUNDERS P.: A comparison of clustering algorithms applied to color image quantization , Pattern Recognition Letters, 18 (1997), 1379-1384 Braquelaire J.P., Brun, L.: Comparison and Optimization of Methods of Color Image Quantization. IEEE trans. on Image Processing. 6(7)(1997), 1048-1052 Sirisathitkul Y., Auwatanamongkol S., Uyyanonvara B.: Color image quantization using distances between adjacent colors along the color axis with highest color variance. Pattern

Recognition Letters. 25 (2004), 1025-1043 Sharma G., Trussell H.J.: Digital Color Imaging. IEEE Trans. on Image Processing. 6(7)(1997), 901-932 8. Linde Y., Buzo A., Gray R.: An algorithm for vector quantizer design. IEEE Trans. on Comm. 28 (1)(1980), 84-95 9. Liu, C.H., Lu, Z.M., Sun, S.H.: An Equal-Average Equal-Norm Nearest Neighbor Codeword Search Algorithm for Vector Quantization. Acta Electronica Sinica (Published in China), 31 (10) (2003) 1558-1561 10. Huang C.M., Bi Q., Stiles G.S., Harris R.W.: Fast full search equivalent encoding algorithms for image compression using vector quantization. IEEE trans. on Image Processing, 1(3)(1992), 413-416 11. Zhang X., Song Z.M., Wang Y.L., Wang H.: Color Quantization of Digital images, in Proc. of PCM2005, LNCS 3768 (2005), 653-664 7.

Você também pode gostar