Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis †
Abstract
1. Introduction
2. Ease of Use
- Efficient Color Palette ExtractionThe use of a modified k-means clustering algorithm allows for more accurate color palette extraction by considering the hue and saturation components of the image colors. This simplifies the process for users, enabling them to obtain a representative color palette without complex manual intervention [3].
- Intuitive User InterfaceWith a palette-based approach, users can easily edit image colors by adjusting the generated palette. This method enables more intuitive and efficient color manipulation compared to traditional techniques [4].
- Preservation of Original Color CharacteristicsGradient analysis helps maintain smooth and natural color transitions in cartoon images, ensuring that the recolored results remain consistent with the original visual characteristics without requiring extensive manual adjustments.
- Flexibility in Color EditingThis method allows users to adjust colors flexibly by editing the generated palette, enabling the exploration of various color schemes without compromising picture quality. The N-dimensional probabilistic histogram-based color transfer method has been proven effective in maintaining color consistency during image recoloring [5]. The Related Work section discusses this as one of the relevant methods for transfer-based recoloring [6]
- Palette-Based Coloring MethodThis study demonstrates the effectiveness of using color palettes in image reconstruction. The color palette serves as the primary color representation, enabling color manipulation without altering the original structure of the image [7].
- Color Segmentation with K-MeansK-means has been widely used in various image processing applications to automatically group colors. This technique enables the efficient extraction of dominant colors, making it applicable to various types of images [8].
- Gradient Analysis in Image ColoringGradient analysis helps preserve important details in the recolorization process, ensuring that colors remain consistent with the original image characteristics.
3. Methodology
3.1. Data Collection and Preparation
3.2. Color Palette Extraction
3.3. Gradient Analysis and Segmentation
3.4. Mapping and Recolorization
3.5. Qualitative and Quantitative Evalutions
- Qualitative Evaluation: Conducted by gathering feedback from users or cartoon artists regarding the suitability and aesthetics of the recolorization result [15].
- Quantitative Evaluation: Using metrics such as the Color Difference Metric (e.g., ∆E in the CIE-Lab Color Space) to measure color differences.
3.6. Implementation and Validation
3.7. Colored Character Binarization Method
- K-Means Clustering: Applying k-means clustering to image pixels in the HSI color space to generate multiple clusters. Each dichotomy in these clusters produces a temporarily binarized image.
- Evaluation with SVM: Using SVM to assess each temporarily binarized image, determining the extent to which the image represents a character or non-character.
- Optimal Image Selection: Selecting the binarized image with the highest “character similarity” level as the optimal binarization result.
4. Implementation
- Implementation of the Linear Segmentation MethodThe Linear Segmentation method in the code is implemented through the function get_palette(image, k = 7), which segments the image based on the dominant color clusters using the k-means clustering algorithm.
- Color Segmentation ProcessThe initial image in BGR format is converted to RGB using cv2.cvtColor(image, cv2.COLOR_BGR2RGB) because OpenCV uses BGR as the default format; k-means works better in RGB format.
- Reshape DataThe image is converted into a 2D array (image_flat) with the shape (number of pixels) so that each pixel can be analyzed independently.
- Clustering with K-Means.The k-means clustering algorithm is used to divide the image colors into k = 7 main color groups. The function is KMeans(n_clusters=k, n_init=10, random_state=42). fit(image_flat) is applied to identify the dominant color cluster centers. The k-means clustering algorithm segments the image into multiple clusters based on the color features, which are then used to generate a color palette for the recoloring task [18].
- Image SegmentationThe classified image is converted back to its original form using the cluster labels obtained from kmeans.labels_.reshape. The segmentation results are visualized using visualize_segmented_image, which applies the “jet” colormap to highlight color regions grouped based on the k-means results.
- Visualize the Color Palette With GradationAfter extracting the dominant colors, the next step is to visualize the color palette in the form of a gradient to understand the resulting color transitions [19].
- Recoloring Images With Color Palette MappingThe image to be recolored is adjusted to the extracted color palette by mapping each pixel to the nearest color in the palette. The k-means method is also applied in image-based text processing, as seen in studies that use this approach for the binarization of colored character strings in scene images [4].
4.1. Experiments and Results
4.2. Discussion and Comparison
5. Conclusions
- Accurate color palette extraction: By applying k-means clustering, this method can identify and group dominant colors in an image, resulting in a palette that is more representative of the original colors.
- Preservation of visual details: Gradient analysis helps maintain smooth color transitions without disrupting important elements in the image, especially along edges and areas with significant color changes.
- Ease of color manipulation: With a palette-based system, users have greater flexibility in adjusting color combinations without the need for complex manual modifications.
- Efficiency in the recolorization process: This method enables faster and more organized color changes compared to traditional approaches, making it suitable for various creative industry applications such as animation, graphic design, and game development.
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Wu, Z.; Xue, R. Color Transfer with Salient Features Mapping via Attention Maps between Images. IEEE Access 2020, 8, 104884–104892. [Google Scholar] [CrossRef]
- IEEE. IEEE 4th International Conference on Signal and Image Processing (ICSIP 2019); IEEE: Piscataway, NJ, USA, 2019. [Google Scholar]
- IEEE. Annual Conference on New Trends in Information and Communications Technology Applications (NTICT); IEEE: Piscataway, NJ, USA, 2017. [Google Scholar]
- Zhang, Q.; Xiao, C.; Sun, H.; Tang, F. Palette-Based Image Recoloring Using Color Decomposition Optimization. IEEE Trans. Image Process. 2017, 26, 1952–1964. [Google Scholar] [CrossRef] [PubMed]
- Pitié, F.; Kokaram, A.C.; Dahyot, R. N-dimensional probability density function transfer and its application to color transfer. In Proceedings of the Tenth IEEE International Conference on Computer Vision (ICCV 2005), Beijing, China, 17–20 October 2005; Volume 2, pp. 1434–1439. [Google Scholar] [CrossRef]
- Chang, Y.; Saito, S.; Nakajima, M. Example-based color transformation of image and video using basic color categories. IEEE Trans. Image Process. 2007, 16, 329–336. [Google Scholar] [CrossRef] [PubMed]
- Poco, J.; Mayhua, A.; Heer, J. Extracting and Retargeting Color Mappings from Bitmap Images of Visualizations. IEEE Trans. Vis. Comput. Graph. 2018, 24, 637–646. [Google Scholar] [CrossRef] [PubMed]
- Ilea, D.E.; Whelan, P.F. Color Image Segmentation Using a Spatial K-Means Clustering Algorithm. In Proceedings of the 10th International Machine Vision and Image Processing Conference (IMVIP 2006), Dublin, Ireland, 30 August–1 September 2006. [Google Scholar]
- Choi, Y. Anime Face Dataset. Available online: https://www.kaggle.com/splcher/animefacedataset (accessed on 4 September 2025).
- Lertrusdachakul, T.; Ruxpaitoon, K.; Thiptarajan, K. Color Palette Extraction by Using Modified K-means Clustering. In Proceedings of the 2019 7th International Electrical Engineering Congress (iEECON), Hua Hin, Thailand, 6–8 March 2019. [Google Scholar]
- Xuan, L.; Zhang, H. An Improved Canny Edge Detection Algorithm. In Proceedings of the 2014 IEEE International Conference on Mechatronics and Automation, Tianjin, China, 3–6 August 2014. [Google Scholar]
- IEEE. 9th International Congress on Image and Signal Processing, BioMedical Engineering and Informatics (CISP-BMEI); IEEE: Piscataway, NJ, USA, 2016. [Google Scholar]
- Mandic, L.; Grgic, S.; Grgic, M. Comparison of Color Difference Equations. In Proceedings of the Proceedings ELMAR 2006, Zadar, Croatia, 7–10 June 2006. [Google Scholar]
- Ul Hasan, N.; Ejaz, W.; Ejaz, N.; Kim, H.S.; Anpalagan, A.; Jo, M. Network Selection and Channel Allocation for Spectrum Sharing in 5G Heterogeneous Networks. IEEE Access 2016, 4, 980–992. [Google Scholar] [CrossRef]
- Zhang, X.; Silverstein, D.A.; Farrell, J.E.; Wandell, B.A. Color image quality metric S-CIELAB and its application on halftone texture visibility. In Proceedings of the IEEE COMPCON ’97, San Jose, CA, USA, 24–27 February 1997; pp. 44–48. [Google Scholar] [CrossRef]
- Arabnia, H.; Deligiannidis, L.; Yang, M.Q. International Conference on Computational Science and Computational Intelligence: CSCI 2016: Proceedings: 15–17 December 2016, Las Vegas, NV, USA; IEEE Computer Society, Conference Publishing Services: Los Alamitos, CA, USA, 2016. [Google Scholar]
- Wakahara, T.; Kita, K. Binarization of color character strings in scene images using K-means clustering and support vector machines. In Proceedings of the International Conference on Document Analysis and Recognition (ICDAR), Beijing, China, 18–21 September 2011; pp. 274–278. [Google Scholar] [CrossRef]
- Lucchese, L.; Mitra, S. Unsupervised Segmentation of Color Images Based on K-means Clustering in the Chromaticity Plane. In Proceedings of the Proceedings IEEE Workshop on Content-Based Access of Image and Video Libraries (CBAIVL’99), Fort Collins, CO, USA, 22–22 June 1999. [Google Scholar]
- Mikamo, M.; Tsuda, Y.; Raytchev, B.; Tamaki, T.; Kaneda, K. An efficient method for displaying compressed HDR spectral images to RGB display monitors. In Proceedings of the 2012 3rd International Conference on Networking and Computing (ICNC 2012), Okinawa, Japan, 5–7 December 2012; pp. 169–174. [Google Scholar] [CrossRef]
- Yuan, L.; Xu, X. Adaptive Image Edge Detection Algorithm Based on Canny Operator. In Proceedings of the 2015 4th International Conference on Advanced Information Technology and Sensor Application (AITS 2015), Harbin, China, 19–20 December 2015; pp. 28–31. [Google Scholar] [CrossRef]
- Pickard, W.F. Massive electricity storage for a developed economy of ten billion people. IEEE Access 2015, 3, 1392–1407. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 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 (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Sujjada, A.; Fauzi, M.R.; Suriawan, A.R.A.; Suhaimi, D.M. Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis. Eng. Proc. 2025, 107, 82. https://doi.org/10.3390/engproc2025107082
Sujjada A, Fauzi MR, Suriawan ARA, Suhaimi DM. Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis. Engineering Proceedings. 2025; 107(1):82. https://doi.org/10.3390/engproc2025107082
Chicago/Turabian StyleSujjada, Alun, Mochamad Rizky Fauzi, Abrar Ramadava Algadri Suriawan, and Dilfa Mahmood Suhaimi. 2025. "Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis" Engineering Proceedings 107, no. 1: 82. https://doi.org/10.3390/engproc2025107082
APA StyleSujjada, A., Fauzi, M. R., Suriawan, A. R. A., & Suhaimi, D. M. (2025). Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis. Engineering Proceedings, 107(1), 82. https://doi.org/10.3390/engproc2025107082