# Fast Color Quantization by K-Means Clustering Combined with Image Sampling

^{*}

## Abstract

**:**

## 1. Introduction

- An improved color quantization method may result in high image quality and short quantization time simultaneously.
- Our method limits its working area to the stage of determining the color palette (initialization, clustering) to the image downsampled by the Nearest Neighbor Interpolation (NNI).
- The quality indices of our quantized images compared with results for the method based on a limited sample of pixels (coreset-based algorithm) show an advantage of our method.

## 2. Related Work

## 3. The Proposed Method

- Initialization of the KM algorithm with cluster centers from Wu’s algorithm,
- For each pixel ${x}_{i}$ that represents RGB components, compute its membership $m\left({c}_{k}\right|{x}_{i})$ in each cluster center ${c}_{k}$:$$m\left({c}_{k}\right|{x}_{i})=\left\{\begin{array}{c}1,\phantom{\rule{1.em}{0ex}}\mathrm{if}\phantom{\rule{1.em}{0ex}}l=arg\underset{k}{min}{\u2225{x}_{i}-{c}_{k}\u2225}^{2},\hfill \\ 0,\phantom{\rule{1.em}{0ex}}\mathrm{otherwise},\hfill \end{array}\right.$$
- Recompute location of each center ${c}_{k}$ from all pixels ${x}_{i}$ based on their memberships:$${c}_{k}=\frac{{\sum}_{i=1}^{n}m\left({c}_{k}\right|{x}_{i}){x}_{i}}{{\sum}_{i=1}^{n}m\left({c}_{k}\right|{x}_{i})},$$
- Repeat two former stages until convergence.

## 4. Experimental Results

## 5. Conclusions

## Author Contributions

## Funding

## Conflicts of Interest

## References

- Heckbert, P. Color image quantization for frame buffer display. ACM SIGGRAPH Comput. Graph.
**1982**, 16, 297–307. [Google Scholar] [CrossRef] [Green Version] - Wu, X. Efficient statistical computations for optimal color quantization. In Graphic Gems II; Arvo, J., Ed.; Academic Press: New York, NY, USA, 1991; pp. 126–133. [Google Scholar]
- MacQueen, J. Some methods for classification and analysis of multivariate observations. In Proceedings of the 5th Berkeley Symposium on Mathematics, Statistics, and Probabilities; University of California Press: Berkeley, CA, USA, 1967; pp. 281–297. [Google Scholar]
- Palus, H.; Frackiewicz, M. New approach for initialization of k-means technique applied to color quantization. In Proceedings of the 2010 2nd International Conference on Information Technology, (2010 ICIT), Gdansk, Poland, 28–30 June 2010; pp. 205–209. [Google Scholar]
- Kanungo, T.; Mount, D.M.; Netanyahu, N.S.; Piatko, C.D.; Silverman, R.; Wu, A.Y. An efficient k-means clustering algorithm: Analysis and implementation. IEEE Trans. Pattern Anal. Mach. Intell.
**2002**, 7, 881–892. [Google Scholar] [CrossRef] - Bejarano, J.; Bose, K.; Brannan, T.; Thomas, A.; Adragni, K.; Neerchal, N.K.; Ostrouchov, G. Sampling within k-Means Algorithm to Cluster Large Datasets; UMBC Student Collection, University of Maryland: Baltimore, MD, USA, 2011. [Google Scholar]
- Sinha, P.K. Image Acquisition and Preprocessing for Machine Vision Systems; International Society for Optics and Photonics (SPIE): Bellingham, WA, USA, 2012. [Google Scholar]
- Papamarkos, N.; Atsalakis, A.E.; Strouthopoulos, C.P. Adaptive color reduction. IEEE Trans. Syst. Man Cybern. Part B Cybern.
**2002**, 32, 44–56. [Google Scholar] [CrossRef] [PubMed] - Szilágyi, L.; Dénesi, G.; Szilágyi, S.M. Fast color reduction using approximative c-means clustering models. In Proceedings of the 2014 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), Beijing, China, 6–11 July 2014; pp. 194–201. [Google Scholar]
- Valenzuela, G.; Celebi, M.E.; Schaefer, G. Color quantization using coreset sampling. In Proceedings of the 2018 IEEE International Conference on Systems, Man, and Cybernetics, Miyazaki, Japan, 7–10 October 2018; pp. 2096–2101. [Google Scholar]
- Arthur, D.; Vassilvitskii, S. k-means++: The advantages of careful seeding. In Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, New Orleans, LA, USA, 7–9 January 2007; pp. 1027–1035. [Google Scholar]
- Lucic, M.; Bachem, O.; Krause, A. Strong Coresets for Hard and Soft Bregman Clustering with Applications to Exponential Family Mixtures. arXiv
**2015**, arXiv:1508.05243. [Google Scholar] - Gerstner, T.; DeCarlo, D.; Alexa, M.; Finkelstein, A.; Gingold, Y.; Nealen, A. Pixelated image abstraction with integrated user constraints. Comput. Graph.
**2013**, 37, 333–347. [Google Scholar] [CrossRef] - Ahn, J.; Park, J.; Park, D.; Paek, J.; Ko, J. Convolutional neural network-based classification system design with compressed wireless sensor network images. PLoS ONE
**2018**, 13, e0196251. [Google Scholar] [CrossRef] [PubMed] - Celebi, M.E. Partitional Clustering Algorithms; Springer: Berlin, Germany, 2014. [Google Scholar]
- Timmerman, B. Wu’s Color Quantizer. Available online: https://gist.github.com/bert/1192520 (accessed on 22 July 2019).
- Lee, D.; Plataniotis, K.N. Towards a full-reference quality assessment for color images using directional statistics. Image Process. IEEE Trans.
**2015**, 24, 3950–3965. [Google Scholar] - Reisenhofer, R.; Bosse, S.; Kutyniok, G.; Wiegand, T. A Haar Wavelet-Based Perceptual Similarity Index for Image Quality Assessment. arXiv
**2016**, arXiv:1607.06140. [Google Scholar] [CrossRef] - Frackiewicz, M.; Palus, H. New image quality metric used for the assessment of color quantization algorithms. In Proceedings of the Ninth International Conference on Machine Vision, SPIE, Nice, France, 18–20 November 2016; p. 103411G. [Google Scholar]
- Palus, H.; Frackiewicz, M. Further applications of the DSCSI metric for evaluating color quantization. In Proceedings of the Ninth International Conference on Machine Vision, SPIE, Nice, France, 18–20 November 2016; p. 103411H. [Google Scholar]
- Frackiewicz, M.; Palus, H. K-Means color image quantization with deterministic initialization: New image quality metrics. In Proceedings of the International Conference Image Analysis and Recognition, Povoa de Varzim, Portugal, 27–29 June 2018; pp. 56–61. [Google Scholar]
- Kodak Images. Available online: http://r0k.us/graphics/kodak/ (accessed on 22 July 2019).

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 378 | 378 | 378 | 126 | 120 | 120 | 234 | 233 | 233 | 204 | 203 | 203 |

1/2 | 379 | 383 | 385 | 124 | 121 | 123 | 233 | 232 | 236 | 210 | 205 | 206 |

1/4 | 376 | 382 | 395 | 123 | 122 | 124 | 233 | 234 | 240 | 208 | 205 | 208 |

1/8 | 381 | 385 | 398 | 123 | 122 | 125 | 237 | 235 | 244 | 206 | 203 | 208 |

1/16 | 392 | N/A | N/A | 121 | N/A | N/A | 238 | N/A | N/A | 207 | N/A | N/A |

1/32 | 388 | N/A | N/A | 123 | N/A | N/A | 238 | N/A | N/A | 207 | N/A | N/A |

1/64 | 384 | N/A | N/A | 123 | N/A | N/A | 237 | N/A | N/A | 207 | N/A | N/A |

1/128 | 412 | N/A | N/A | 122 | N/A | N/A | 242 | N/A | N/A | 207 | N/A | N/A |

1/256 | 400 | N/A | N/A | 132 | N/A | N/A | 249 | N/A | N/A | 212 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 240 | 238 | 238 | 75 | 73 | 73 | 138 | 137 | 137 | 117 | 114 | 114 |

1/2 | 241 | 242 | 248 | 73 | 74 | 79 | 140 | 137 | 141 | 115 | 114 | 117 |

1/4 | 243 | 243 | 251 | 75 | 74 | 77 | 140 | 138 | 144 | 113 | 115 | 117 |

1/8 | 247 | 245 | 258 | 75 | 75 | 79 | 140 | 139 | 146 | 114 | 115 | 121 |

1/16 | 243 | N/A | N/A | 75 | N/A | N/A | 139 | N/A | N/A | 113 | N/A | N/A |

1/32 | 249 | N/A | N/A | 75 | N/A | N/A | 138 | N/A | N/A | 117 | N/A | N/A |

1/64 | 249 | N/A | N/A | 76 | N/A | N/A | 142 | N/A | N/A | 116 | N/A | N/A |

1/128 | 256 | N/A | N/A | 78 | N/A | N/A | 143 | N/A | N/A | 120 | N/A | N/A |

1/256 | 263 | N/A | N/A | 80 | N/A | N/A | 154 | N/A | N/A | 124 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 156 | 152 | 152 | 48 | 47 | 47 | 85 | 84 | 84 | 69 | 67 | 67 |

1/2 | 157 | 157 | 162 | 48 | 47 | 49 | 85 | 86 | 89 | 68 | 68 | 70 |

1/4 | 157 | 158 | 167 | 48 | 48 | 51 | 86 | 87 | 92 | 69 | 68 | 71 |

1/8 | 158 | 160 | 172 | 48 | 49 | 52 | 86 | 88 | 94 | 68 | 69 | 73 |

1/16 | 157 | N/A | N/A | 48 | N/A | N/A | 87 | N/A | N/A | 68 | N/A | N/A |

1/32 | 159 | N/A | N/A | 49 | N/A | N/A | 87 | N/A | N/A | 69 | N/A | N/A |

1/64 | 163 | N/A | N/A | 50 | N/A | N/A | 90 | N/A | N/A | 71 | N/A | N/A |

1/128 | 172 | N/A | N/A | 52 | N/A | N/A | 95 | N/A | N/A | 73 | N/A | N/A |

1/256 | 174 | N/A | N/A | 54 | N/A | N/A | 100 | N/A | N/A | 76 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 99 | 97 | 97 | 31 | 30 | 30 | 54 | 54 | 54 | 42 | 41 | 41 |

1/2 | 100 | 101 | 107 | 31 | 31 | 33 | 54 | 56 | 59 | 42 | 42 | 44 |

1/4 | 100 | 103 | 109 | 31 | 32 | 34 | 54 | 57 | 61 | 42 | 43 | 45 |

1/8 | 101 | 105 | 114 | 31 | 33 | 35 | 55 | 58 | 63 | 42 | 44 | 47 |

1/16 | 102 | N/A | N/A | 32 | N/A | N/A | 56 | N/A | N/A | 42 | N/A | N/A |

1/32 | 105 | N/A | N/A | 32 | N/A | N/A | 57 | N/A | N/A | 43 | N/A | N/A |

1/64 | 108 | N/A | N/A | 34 | N/A | N/A | 59 | N/A | N/A | 45 | N/A | N/A |

1/128 | 113 | N/A | N/A | 35 | N/A | N/A | 64 | N/A | N/A | 47 | N/A | N/A |

1/256 | 119 | N/A | N/A | 38 | N/A | N/A | 68 | N/A | N/A | 50 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 345 | 443 | 443 | 124 | 477 | 477 | 154 | 474 | 474 | 828 | 647 | 647 |

1/2 | 155 | 1370 | 116 | 62 | 1499 | 121 | 79 | 1327 | 102 | 134 | 3201 | 233 |

1/4 | 201 | 696 | 55 | 40 | 841 | 64 | 50 | 684 | 52 | 49 | 1634 | 122 |

1/8 | 45 | 368 | 57 | 20 | 400 | 31 | 30 | 356 | 28 | 52 | 825 | 68 |

1/16 | 15 | N/A | N/A | 21 | N/A | N/A | 12 | N/A | N/A | 16 | N/A | N/A |

1/32 | 9 | N/A | N/A | 13 | N/A | N/A | 4 | N/A | N/A | 11 | N/A | N/A |

1/64 | 6 | N/A | N/A | 4 | N/A | N/A | 2 | N/A | N/A | 5 | N/A | N/A |

1/128 | 2 | N/A | N/A | 4 | N/A | N/A | 1 | N/A | N/A | 3 | N/A | N/A |

1/256 | 2 | N/A | N/A | 2 | N/A | N/A | 1 | N/A | N/A | 3 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 326 | 849 | 849 | 213 | 884 | 844 | 154 | 842 | 842 | 565 | 1334 | 1334 |

1/2 | 199 | 1436 | 123 | 249 | 1513 | 120 | 79 | 1418 | 129 | 389 | 3313 | 252 |

1/4 | 101 | 754 | 64 | 72 | 798 | 71 | 50 | 759 | 67 | 367 | 1697 | 138 |

1/8 | 34 | 382 | 34 | 34 | 427 | 34 | 30 | 509 | 36 | 146 | 871 | 74 |

1/16 | 30 | N/A | N/A | 13 | N/A | N/A | 12 | N/A | N/A | 77 | N/A | N/A |

1/32 | 18 | N/A | N/A | 11 | N/A | N/A | 4 | N/A | N/A | 21 | N/A | N/A |

1/64 | 11 | N/A | N/A | 10 | N/A | N/A | 2 | N/A | N/A | 11 | N/A | N/A |

1/128 | 6 | N/A | N/A | 4 | N/A | N/A | 1 | N/A | N/A | 6 | N/A | N/A |

1/256 | 3 | N/A | N/A | 2 | N/A | N/A | 1 | N/A | N/A | 3 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 471 | 1706 | 1706 | 247 | 1657 | 1657 | 750 | 1598 | 1598 | 800 | 2492 | 2492 |

1/2 | 233 | 1584 | 156 | 188 | 1626 | 150 | 307 | 1461 | 146 | 486 | 3484 | 286 |

1/4 | 146 | 814 | 79 | 125 | 836 | 89 | 221 | 881 | 76 | 198 | 1805 | 157 |

1/8 | 59 | 434 | 47 | 47 | 488 | 45 | 77 | 411 | 46 | 196 | 950 | 88 |

1/16 | 66 | N/A | N/A | 31 | N/A | N/A | 38 | N/A | N/A | 86 | N/A | N/A |

1/32 | 49 | N/A | N/A | 20 | N/A | N/A | 32 | N/A | N/A | 31 | N/A | N/A |

1/64 | 17 | N/A | N/A | 10 | N/A | N/A | 16 | N/A | N/A | 16 | N/A | N/A |

1/128 | 8 | N/A | N/A | 5 | N/A | N/A | 7 | N/A | N/A | 10 | N/A | N/A |

1/256 | 4 | N/A | N/A | 3 | N/A | N/A | 3 | N/A | N/A | 6 | N/A | N/A |

$\mathit{c}\mathit{f},\mathit{d}\mathit{f}$ | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 | NNI | CM2 | CM4 |
---|---|---|---|---|---|---|---|---|---|---|---|---|

Baboon | Lena | Peppers | Pills | |||||||||

1 | 1260 | 3152 | 3152 | 1124 | 3026 | 3026 | 1390 | 2929 | 2929 | 3223 | 4606 | 4606 |

1/2 | 526 | 1796 | 190 | 339 | 2137 | 205 | 564 | 1673 | 186 | 875 | 3830 | 364 |

1/4 | 368 | 898 | 105 | 281 | 1047 | 111 | 572 | 890 | 98 | 612 | 1989 | 199 |

1/8 | 209 | 522 | 58 | 143 | 575 | 70 | 144 | 490 | 58 | 308 | 1046 | 108 |

1/16 | 93 | N/A | N/A | 55 | N/A | N/A | 113 | N/A | N/A | 243 | N/A | N/A |

1/32 | 61 | N/A | N/A | 35 | N/A | N/A | 49 | N/A | N/A | 65 | N/A | N/A |

1/64 | 34 | N/A | N/A | 21 | N/A | N/A | 29 | N/A | N/A | 28 | N/A | N/A |

1/128 | 11 | N/A | N/A | 10 | N/A | N/A | 9 | N/A | N/A | 25 | N/A | N/A |

1/256 | 5 | N/A | N/A | 4 | N/A | N/A | 4 | N/A | N/A | 7 | N/A | N/A |

$\mathit{d}\mathit{f}$ | k | |||
---|---|---|---|---|

32 | 64 | 128 | 256 | |

1 | 361 | 650 | 1465 | 2500 |

1/2 | 161 | 366 | 643 | 1106 |

1/4 | 80 | 177 | 347 | 565 |

1/8 | 46 | 76 | 165 | 298 |

1/16 | 22 | 44 | 75 | 134 |

1/32 | 11 | 21 | 37 | 68 |

1/64 | 6 | 11 | 19 | 32 |

1/128 | 3 | 5 | 7 | 15 |

1/256 | 2 | 3 | 4 | 7 |

© 2019 by the authors. 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**

Frackiewicz, M.; Mandrella, A.; Palus, H.
Fast Color Quantization by K-Means Clustering Combined with Image Sampling. *Symmetry* **2019**, *11*, 963.
https://doi.org/10.3390/sym11080963

**AMA Style**

Frackiewicz M, Mandrella A, Palus H.
Fast Color Quantization by K-Means Clustering Combined with Image Sampling. *Symmetry*. 2019; 11(8):963.
https://doi.org/10.3390/sym11080963

**Chicago/Turabian Style**

Frackiewicz, Mariusz, Aron Mandrella, and Henryk Palus.
2019. "Fast Color Quantization by K-Means Clustering Combined with Image Sampling" *Symmetry* 11, no. 8: 963.
https://doi.org/10.3390/sym11080963