Skip to main content

Fast color quantization using MacQueen’s k-means algorithm

Abstract

Color quantization (CQ) is an important operation with many applications in computer graphics and image processing and analysis. Clustering algorithms have been extensively applied to this problem. However, despite its popularity as a general purpose clustering algorithm, k-means has not received much attention in the CQ literature because of its high computational requirements and sensitivity to initialization. In this paper, we propose a novel CQ method based on an online k-means formulation due to MacQueen. The proposed method utilizes adaptive and efficient cluster center initialization and quasirandom sampling to attain deterministic, high speed, and high-quality quantization. Experiments on a diverse set of publicly available images demonstrate that the proposed method is significantly faster than the more common batch k-means formulation due to Lloyd while delivering nearly identical results.

This is a preview of subscription content, access via your institution.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8

Notes

  1. Strictly speaking, in practice, data sets are not implemented as sets, but as sequences, where elements are ordered and duplicates are allowed. This is especially true for image data sets, which are often stored and accessed in raster order.

  2. In MacQueen’s algorithm, each unit has its own learning rate, which quantifies the number of times that unit won the competition.

  3. The source code of the proposed method is available at https://github.com/skythomp16/MacQueen-Color-Quantization

References

  1. Banerjee, A., Merugu, S., Dhillon, I.S., Ghosh, J.: Clustering with Bregman divergences. J. Mach. Learn. Res. 6, 1705–1749 (2005)

    MathSciNet  MATH  Google Scholar 

  2. Bermejo, S., Cabestany, J.: The effect of finite sample size on online K-means. Neurocomputing 48(1–4), 511–539 (2002)

    MATH  Google Scholar 

  3. Bottou, L.: Online learning and stochastic approximations. In: Saad, D. (ed.) On-Line Learning in Neural Networks, pp. 9–42. Cambridge University Press, Cambridge (1998)

    MATH  Google Scholar 

  4. Bratley, P., Fox, B.L.: Algorithm 659: implementing Sobol’s quasirandom sequence generator. ACM Trans. Math. Softw. 14(1), 88–100 (1988)

    MathSciNet  MATH  Google Scholar 

  5. Braudaway, G.W.: Procedure for optimum choice of a small number of colors from a large color palette for color imaging. In: Proceedings of the Electronic Imaging Conference, pp. 71–75 (1987)

  6. Brun, L., Mokhtari, M.: Two high speed color quantization algorithms. In: Proceedings of the 1st International Conference on Color in Graphics and Image Processing, pp. 116–121 (2000)

  7. Brun, L., Trémeau, A.: Color quantization. In: Sharma, G. (ed.) Digital Color Imaging Handbook, pp. 589–638. CRC Press, Boca Raton (2002)

    Google Scholar 

  8. Celebi, M.E., Wen, Q., Hwang, S.: An effective real-time color quantization method based on divisive hierarchical clustering. J. Real-Time Image Proc. 10(2), 329–344 (2015)

    Google Scholar 

  9. Celebi, M.E.: Fast color quantization using weighted sort-means clustering. J. Opt. Soc. Am. A 26(11), 2434–2443 (2009)

    Google Scholar 

  10. Celebi, M.E.: Improving the performance of K-means for color quantization. Image Vis. Comput. 29(4), 260–271 (2011)

    Google Scholar 

  11. Celebi, M.E., Wen, Q., Schaefer, G., Zhou, H.: Batch neural gas with deterministic initialization for color quantization. In: Proceedings of the International Conference on Computer Vision and Graphics, pp. 48–54 (2012)

  12. Celebi, M.E., Hwang, S., Wen, Q.: Color quantization using the adaptive distributing units algorithm. Imaging Sci. J. 62(2), 80–91 (2014)

    Google Scholar 

  13. Celebi, M.E., Kingravi, H.A., Vela, P.A.: A comparative study of efficient initialization methods for the K-means clustering algorithm. Expert Syst. Appl. 40(1), 200–210 (2013)

    Google Scholar 

  14. Celebi, M.E. (ed.): Partitional Clustering Algorithms. Springer, Berlin (2015)

    MATH  Google Scholar 

  15. Cheng, S., Yang, C.: Fast and novel technique for color quantization using reduction of color space dimensionality. Pattern Recogn. Lett. 22(8), 845–856 (2001)

    MATH  Google Scholar 

  16. Chung, K.L., Huang, Y.H., Wang, J.P., Cheng, M.S.: Speedup of color palette indexing in self-organization of Kohonen feature map. Expert Syst. Appl. 39(3), 2427–2432 (2012)

    Google Scholar 

  17. Dekker, A.: Kohonen neural networks for optimal colour quantization. Network Comput. Neural Syst. 5(3), 351–367 (1994)

    MathSciNet  MATH  Google Scholar 

  18. Darken, C., Moody, J.: Fast adaptive K-means clustering: some empirical results. In: Proceedings of the 1990 International Joint Conference on Neural Networks, vol. 2, pp. 233–238 (1990)

  19. Du, Q., Wong, T.W.: Numerical studies of MacQueen’s K-means algorithm for computing the centroidal Voronoi tessellations. Comput. Math. Appl. 44(3–4), 511–523 (2002)

    MathSciNet  MATH  Google Scholar 

  20. El-Said, S.A.: Image quantization using improved artificial fish swarm algorithm. Soft. Comput. 19(9), 2667–2679 (2015)

    Google Scholar 

  21. Frackiewicz, M., Palus, H.: KM and KHM clustering techniques for colour image quantisation. In: Tavares, J.M.R.S., Jorge, R.M.N. (eds.) Computational Vision and Medical Image Processing: Recent Trends. Springer, pp. 161–174 (2011)

  22. Gervautz, M., Purgathofer, W.: A simple method for color quantization: octree quantization. In: Magnenat-Thalmann, N., Thalmann, D. (eds.) New Trends in Computer Graphics. Springer, pp. 219–231 (1988)

  23. Gonzalez, T.F.: Clustering to minimize the maximum intercluster distance. Theor. Comput. Sci. 38(2–3), 293–306 (1985)

    MathSciNet  MATH  Google Scholar 

  24. Gonzalez, A.I., Grana, M., Albizuri, F.X., D’Anjou, A., Torrealdea, F.J.: A near real-time evolution-based adaptation strategy for dynamic color quantization of image sequences. Inf. Sci. 122(2–4), 161–183 (2000)

    MATH  Google Scholar 

  25. Grossberg, S.: Competitive learning: from interactive activation to adaptive resonance. Cogn. Sci. 11(1), 23–63 (1987)

    Google Scholar 

  26. Hathaway, R.J., Bezdek, J.C., Huband, J.M.: Maximin initialization for cluster analysis. In: Proceedings of the 11th Iberoamerican Congress in Pattern Recognition, pp. 14–26 (2006)

  27. Heckbert, P.: Color image quantization for frame buffer display. ACM SIGGRAPH Comput. Graph. 16(3), 297–307 (1982)

    Google Scholar 

  28. Hsu, W.L., Nemhauser, G.L.: Easy and hard bottleneck location problems. Discret. Appl. Math. 1(3), 209–215 (1979)

    MathSciNet  MATH  Google Scholar 

  29. Hu, Y.C., Lee, M.G.: K-means based color palette design scheme with the use of stable flags. J. Electron. Imaging 16(3), 033003 (2007)

    Google Scholar 

  30. Hu, Y.C., Su, B.H.: Accelerated K-means clustering algorithm for colour image quantization. Imaging Sci. J. 56(1), 29–40 (2008)

    MathSciNet  Google Scholar 

  31. Hu, Z., Su, Q., Xia, X.: Multiobjective image color quantization algorithm based on self-adaptive hybrid differential evolution. Comput. Intell. Neurosci. 2016, 2450431 (2016)

    Google Scholar 

  32. Jain, A.K., Murty, M.N., Flynn, P.J.: Data clustering: a review. ACM Comput. Surv. 31(3), 264–323 (1999)

    Google Scholar 

  33. Joy, G., Xiang, Z.: Center-cut for color image quantization. Vis. Comput. 10(1), 62–66 (1993)

    Google Scholar 

  34. Lemire, D.: Fast random integer generation in an interval. ACM Trans. Model. Comput. Simul. 29(1), 3:1–3:12 (2019)

    MathSciNet  Google Scholar 

  35. Lloyd, S.: Least squares quantization in PCM. IEEE Trans. Inf. Theory 28(2), 129–136 (1982)

    MathSciNet  MATH  Google Scholar 

  36. MacQueen, J.: Some methods for classification and analysis of multivariate observations. In: Proceedings of the 5th Berkeley Symposium on Mathematical Statistics and Probability, pp. 281–297 (1967)

  37. Matsumoto, M., Nishimura, T.: Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator. ACM Trans. Model. Comput. Simul. 8(1), 3–30 (1998)

    MATH  Google Scholar 

  38. Müllner, D.: Fastcluster: fast hierarchical, agglomerative clustering routines for R and Python. J. Stat. Softw. 53(9), 1–18 (2013)

    Google Scholar 

  39. Omran, M.G.H., Engelbrecht, A.P., Salman, A.: Particle swarm optimization for pattern recognition and image processing. In: Abraham, A., Grosan, C., Ramos, V. (eds.) Swarm Intelligence in Data Mining, pp. 125–151. Springer, Berlin (2006)

    Google Scholar 

  40. Orchard, M., Bouman, C.: Color quantization of images. IEEE Trans. Signal Process. 39(12), 2677–2690 (1991)

    Google Scholar 

  41. Ozturk, C., Hancer, E., Karaboga, D.: Color image quantization: a short review and an application with artificial bee colony algorithm. Informatica 25(3), 485–503 (2014)

    Google Scholar 

  42. Nolle, L., Schaefer, G.: Colour map design through optimization. Eng. Optim. 39(3), 327–343 (2007)

    Google Scholar 

  43. Perez-Delgado, M.L.: Colour quantization with ant-tree. Appl. Soft Comput. 36, 656–669 (2015)

    Google Scholar 

  44. Perez-Delgado, M.L., Gallego, J.A.R.: A two-stage method to improve the quality of quantized images. J. Real-Time Image Process. (2019) (in press)

  45. Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes, 3rd edn. Cambridge University Press, Cambridge (2007)

    MATH  Google Scholar 

  46. Rumelhart, D.E., Zipser, D.: Feature discovery by competitive learning. Cogn. Sci. 9(1), 75–112 (1985)

    Google Scholar 

  47. Schaefer, G., Zhou, H.: Fuzzy clustering for colour reduction in images. Telecommun. Syst. 40(1–2), 17–25 (2009)

    Google Scholar 

  48. Schaefer, G., Nolle, L.: Color quantization. In: Qing, A. (ed.) Differential Evolution: Fundamentals and Applications in Electrical Engineering, pp. 399–405. Wiley, New York (2009)

    Google Scholar 

  49. Schaefer, G., Nolle, L.: A hybrid color quantization algorithm incorporating a human visual perception model. Comput. Intell. 31(4), 684–698 (2015)

    MathSciNet  Google Scholar 

  50. Schaefer, G., Hu, Q., Huiyu, Z., Peters, J.F., Hassanien, A.E.: Rough C-means and fuzzy rough C-means for colour quantisation. Fundam. Inf. Emerg. Comput. 119(1), 113–120 (2012)

    MathSciNet  Google Scholar 

  51. Scheunders, P.: A genetic C-means clustering algorithm applied to color image quantization. Pattern Recogn. 30(6), 859–866 (1997)

    Google Scholar 

  52. Scitovski, R., Sabo, K.: Analysis of the K-means algorithm in the case of data points occurring on the border of two or more clusters. Knowl.-Based Syst. 57, 1–7 (2014)

    Google Scholar 

  53. Spall, J.C.: Introduction to Stochastic Search and Optimization: Estimation, Simulation, and Control. Wiley, Oxford (2003)

    MATH  Google Scholar 

  54. Su, Q., Hu, Z.: Color image quantization algorithm based on self-adaptive differential evolution. Comput. Intell. Neurosci. 2013, 231916 (2013)

    Google Scholar 

  55. Uchiyama, T., Arbib, M.: An algorithm for competitive learning in clustering problems. Pattern Recogn. 27(10), 1415–1421 (1994)

    Google Scholar 

  56. 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. 24(6), 741–756 (2017)

    Google Scholar 

  57. 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, pp. 2096–2101 (2018)

  58. Velho, L., Gomez, J., Sobreiro, M.V.R.: Color image quantization by pairwise clustering. In: Proceedings of the 10th Brazilian Symposium on Computer Graphics and Image Processing, pp. 203–210 (1997)

  59. Wan, S.J., Prusinkiewicz, P., Wong, S.K.M.: Variance-based color image quantization for frame buffer display. Color Res. Appl. 15, 52–58 (1990)

    Google Scholar 

  60. Wen, Q., Celebi, M.E.: Hard versus fuzzy C-means clustering for color quantization. EURASIP J. Adv. Signal Process. 2011, 118–129 (2011)

    Google Scholar 

  61. Wu, X.: Efficient statistical computations for optimal color quantization. In: Arvo, J. (ed.) Graphics Gems, vol. II, pp. 126–133. Academic Press, London (1991)

    Google Scholar 

  62. Wu, K.L., Yang, M.S.: Alternative learning vector quantization. Pattern Recogn. 39(3), 351–362 (2006)

    MATH  Google Scholar 

  63. Xiang, Z.: Color image quantization by minimizing the maximum intercluster distance. ACM Trans. Graph. 16(3), 260–276 (1997)

    Google Scholar 

  64. Xiao, Y., Leung, C.S., Lam, P.M., Ho, T.Y.: Self-organizing map-based color palette for high-dynamic range texture compression. Neural Comput. Appl. 21(4), 639–647 (2012)

    Google Scholar 

  65. Yair, E., Zeger, K., Gersho, A.: Competitive learning and soft competition for vector quantizer design. IEEE Trans. Signal Process. 40(2), 294–309 (1992)

    Google Scholar 

  66. Yang, C.Y., Lin, J.C.: RWM-cut for color image quantization. Comput. Graph. 20(4), 577–588 (1996)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to M. Emre Celebi.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Thompson, S., Celebi, M.E. & Buck, K.H. Fast color quantization using MacQueen’s k-means algorithm. J Real-Time Image Proc 17, 1609–1624 (2020). https://doi.org/10.1007/s11554-019-00914-6

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s11554-019-00914-6

Keywords

  • Color quantization
  • Clustering
  • MacQueen k-means
  • Lloyd k-means