Next Article in Journal
Fruit and Vegetable Recognition Using MobileNetV2: An Image Classification Approach
Previous Article in Journal
A Comprehensive Study on Predicting the Need for Vehicle Maintenance Using Machine Learning
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Proceeding Paper

Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis †

by
Alun Sujjada
*,
Mochamad Rizky Fauzi
,
Abrar Ramadava Algadri Suriawan
and
Dilfa Mahmood Suhaimi
Department of Informatics Engineering, Faculty of Engineering, Computer and Design, Nusa Putra University, Sukabumi 43152, West Java, Indonesia
*
Author to whom correspondence should be addressed.
Presented at the 7th International Global Conference Series on ICT Integration in Technical Education & Smart Society, Aizuwakamatsu City, Japan, 20–26 January 2025.
Eng. Proc. 2025, 107(1), 82; https://doi.org/10.3390/engproc2025107082
Published: 9 September 2025

Abstract

This study introduces a palette-based method for the recolorization of cartoon images by combining the k-means clustering algorithm and gradient analysis. The method aims to preserve the visual identity of the original image while allowing flexibility in color manipulation. By segmenting colors using k-means clustering, the approach produces a representative color palette reflecting the dominant colors in the image. Gradient analysis is then applied to maintain smooth color transitions and aesthetic consistency. This palette serves as the basis for the recolorization process, enabling intuitive color adjustments without disrupting the visual structure of the image. Experimental results demonstrate that this method can produce recolorized images with high visual quality, preserve original image details, and provide users with greater control over the resulting colors.

1. Introduction

Cartoon image recolorization is the process of altering or enhancing the colors of cartoon images to meet aesthetic or artistic requirements. This process has widespread applications in creative industries such as animation, graphic design, and game development. The demand for efficient and high-quality recoloring methods is pressing. Without an appropriate method, the recoloring process can become inconsistent and time-consuming if performed manually. Therefore, this research aims to develop a more effective and structured method for cartoon image recolorization.
In this study, we propose a palette-based approach for cartoon image recolorization that integrates k-means clustering and gradient analysis. K-means clustering, which is also commonly used in hyperspectral data clustering, enables the grouping of pixels based on color similarity, thereby facilitating efficient color manipulation. Meanwhile, gradient analysis is employed to identify important details, such as edges or significant visual changes, ensuring the preservation of the original image quality during the recolorization process [1].
Furthermore, the recolorization process also adopts the principle of color mapping to ensure harmony between the reference color palette and the source image. As explained in research on feature-based color transfer, this step involves the creation of weighted attention maps that integrate gradient information and saliency maps [1]. This technique ensures more accurate color mapping is achieved by considering visually important areas while preserving the details and textures of the image [1]. This article is structured as follows: The first section discusses the background and related methods. The second section explains the proposed palette-based recolorization approach, followed by an experimental evaluation of the results. Finally, we conclude with the advantages, limitations, and potential future research directions.
Previous studies have explored various methods for image recolorization, such as color transfer models and spectral segmentation approaches [2]. However, these methods often struggle to maintain the original visual structure and produce natural color transitions. Therefore, this study proposes a novel approach that combines k-means clustering and gradient analysis to develop a more adaptive and accurate recolorization method for cartoon images. If the proposed method proves effective, it could make a significant contribution to the creative industry, particularly in the development of automated recoloring technology. Conversely, without the development of new methods, the recolorization process will continue to face limitations in flexibility and the visual quality of the final output.

2. Ease of Use

The recoloring method for cartoon images using a palette-based color mapping approach with k-means clustering and gradient analysis offers several advantages in terms of ease of use:
  • Efficient Color Palette Extraction
    The 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 Interface
    With 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 Characteristics
    Gradient 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 Editing
    This 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 Method
    This 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-Means
    K-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 Coloring
    Gradient analysis helps preserve important details in the recolorization process, ensuring that colors remain consistent with the original image characteristics.
By considering differences in color intensity and lighting, this method enhances the quality of the recoloring results.

3. Methodology

The methodology of this research aims to develop and evaluate a palette-based approach designed for the recolorization process of cartoon images. This process utilizes the k-means clustering algorithm for color segmentation and gradient analysis to preserve the integrity of the image design. This study consists of several key stages, which are explained as follows:

3.1. Data Collection and Preparation

This stage includes collecting datasets from open sources, specifically the Anime Face Dataset by Chao [9], and creating additional cartoon images manually; performing image preprocessing, such as resizing images to ensure uniformity; converting the image format to RGB [6]; and removing any potential noise in the images.

3.2. Color Palette Extraction

At this stage, color palette extraction from cartoon images is performed using the k-means clustering algorithm. One relevant approach is a method that modifies k-means by analyzing hue and saturation components to enhance color representation [10]. The image is converted to an appropriate color space. The k-means algorithm is applied to cluster image pixels into several groups based on color values. The centroid colors of each cluster are selected as the color palette representation of the image. The main parameters in k-means include the number of clusters (k), determined through experiments to achieve optimal results. This parameter defines the maximum number of iterations allowed for the algorithm to converge. The modified k-means clustering method can improve the accuracy of color extraction by considering hue and saturation components, as proposed by Lertrusdachakul [10].

3.3. Gradient Analysis and Segmentation

To maintain the integrity of the image design during the recolorization process, gradient analysis is performed. A relevant approach involves using edge detection, such as the Canny method, to distinguish image edges [11]. The application of k-means clustering in image segmentation extends beyond cartoon images and has also proven effective in medical image segmentation, as demonstrated in previous studies on medical tissue color segmentation [12].
Gradients are calculated using edge detection methods to detect image edges and contours. Gradient information is used to divide the image into segments that reflect areas with uniform color patterns. By mapping the color clusters obtained from the segmentation process to a new color palette, it is possible to recolor the cartoon image while preserving its structural integrity and visual coherence [13]. Segmentation helps ensure that the new colors are applied in accordance with the original design structure.

3.4. Mapping and Recolorization

Colors in the old palette are mapped to colors in the new palette using a color distance metric approach (e.g., Euclidean distance in RGB or CIE–Lab Color Space [14]). The algorithm ensures that the new colors replace the old ones while considering color harmonization and gradient-based segmentation.

3.5. Qualitative and Quantitative Evalutions

Evaluations are conducted to assess the effectiveness of the proposed method.
  • 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

The system is implemented using the Python programming language (version 3.9) with libraries such as OpenCV (version 4.8.0), scikit-learn (version 1.2.2), and NumPy (version 1.24.0). Testing is conducted on a dataset to measure the algorithm’s performance in terms of computation time [16] and to ensure the stability of results across various cartoon images.

3.7. Colored Character Binarization Method

Dalam scene image processing, k-means clustering, and Support Vector Machines (SVM) are used. This method consists of three main steps, as follows:
  • 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.
This approach enables the binarization of multicolor characters that have undergone significant degradation, achieving a high success rate in binarization [17]. With this methodology, this study aims to develop an effective and efficient recolorization system that can be widely applied to various cartoon art styles.

4. Implementation

Implementation refers to the method proposed in the study titled “Recoloring Cartoon Images Based on Palette Mapping Using K-Means Clustering and Gradient Analysis”, where modifications were made to the k-means algorithm to improve dominant color extraction.
  • Implementation of the Linear Segmentation Method
    The 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 Process
    The 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 Data
    The 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 Segmentation
    The 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 Gradation
    After 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 Mapping
    The 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].
This approach aligns with the method described in the study “Palette-Based Image Recoloring Using Color Decomposition optimization” [14], where color decomposition is performed to achieve more accurate recolorization [20].

4.1. Experiments and Results

To evaluate the proposed method, two images were employed: the input image, which was used to extract the color palette, and the target image, which was subsequently recolored using the palette derived from the input, as shown in Figure 1 and Figure 2.
The first result generated by the proposed algorithm is the Dominant Color Gradient, as shown in Figure 3.
After the Dominant Color Gradient, the target image is displayed with colors assigned based on the segmentation results obtained using the k-means algorithm, as shown in Figure 4.
The palette-based color mapping method using k-means clustering is effective in extracting dominant colors from cartoon images and applying them to other images while maintaining natural color transitions. K-means clustering has been compared with other clustering methods, such as DBSCAN and agglomerative clustering, in a study by Arabnia [16], demonstrating its effectiveness in grouping pixels based on color characteristics. By adjusting the number of clusters, the recolorization results can be optimized as needed.

4.2. Discussion and Comparison

Several previous studies have proposed various approaches to image recolorization. For example, the salient feature-based color transfer method uses a weighted attention map to map colors from a reference image to a target image. However, this method tends to be less flexible due to its reliance on specific features within the image.
Compared to color transfer-based methods, the palette-based approach used in this study offers greater flexibility in color manipulation. Additionally, the gradient analysis applied in this research enables the better preservation of the structural elements of the image compared to the N-dimensional probabilistic histogram approach, which often overlooks fine details in the image [21].
The experiments conducted show that the proposed method produces recolorization with higher visual quality compared to probabilistic histogram-based methods. By preserving structural elements through gradient analysis, this method also reduces the risk of color distortion that often occurs in histogram-based approaches. This has been discussed within the broadest possible context. Future research directions may also be highlighted.

5. Conclusions

This study successfully developed a palette-based recolorization method utilizing k-means clustering and gradient analysis. Experimental results show that this method not only preserves the original visual structure of the image but also provides greater flexibility in color manipulation.
Based on the research conducted, the palette mapping-based cartoon image recolorization method using k-means clustering and gradient analysis has proven effective in producing images that preserve their original visual structure. Some key points that can be concluded from this study are as follows:
  • 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.
Although this method shows promising results, there are still some limitations, such as selecting the optimal number of clusters in k-means clustering and the potential loss of color details in images with complex gradients. Therefore, further development can be carried out by integrating artificial intelligence or machine learning techniques to improve color mapping accuracy and optimize algorithm performance to be more adaptive to various types of cartoon images.
With the results obtained, this research is expected to serve as a reference for the development of more advanced and efficient digital recolorization techniques in the future.

Author Contributions

Conceptualization, A.S. and M.R.F.; Methodology, A.S.; Software, A.R.A.S.; Validation, A.S., M.R.F. and D.M.S.; Formal Analysis, A.S.; Investigation, A.R.A.S.; Resources, D.M.S.; Data Curation, A.R.A.S.; Writing—Original Draft Preparation, A.S.; Writing—Review and Editing, A.S.; Visualization, A.R.A.S.; Supervision, D.M.S.; Project Administration, M.R.F.; Funding Acquisition, M.R.F. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The data used in this study are openly available as the Anime Face Dataset by Chao [9], which can be accessed at https://www.kaggle.com/splcher/animefacedataset (accessed on 10 August 2025).

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Wu, Z.; Xue, R. Color Transfer with Salient Features Mapping via Attention Maps between Images. IEEE Access 2020, 8, 104884–104892. [Google Scholar] [CrossRef]
  2. IEEE. IEEE 4th International Conference on Signal and Image Processing (ICSIP 2019); IEEE: Piscataway, NJ, USA, 2019. [Google Scholar]
  3. IEEE. Annual Conference on New Trends in Information and Communications Technology Applications (NTICT); IEEE: Piscataway, NJ, USA, 2017. [Google Scholar]
  4. 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]
  5. 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]
  6. 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]
  7. 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]
  8. 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]
  9. Choi, Y. Anime Face Dataset. Available online: https://www.kaggle.com/splcher/animefacedataset (accessed on 4 September 2025).
  10. 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]
  11. 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]
  12. IEEE. 9th International Congress on Image and Signal Processing, BioMedical Engineering and Informatics (CISP-BMEI); IEEE: Piscataway, NJ, USA, 2016. [Google Scholar]
  13. 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]
  14. 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]
  15. 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]
  16. 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]
  17. 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]
  18. 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]
  19. 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]
  20. 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]
  21. Pickard, W.F. Massive electricity storage for a developed economy of ten billion people. IEEE Access 2015, 3, 1392–1407. [Google Scholar] [CrossRef]
Figure 1. Image Input. Cartoon image (AI-generated by the authors using ChatGPT/DALL·E, 2025).
Figure 1. Image Input. Cartoon image (AI-generated by the authors using ChatGPT/DALL·E, 2025).
Engproc 107 00082 g001
Figure 2. Image Target. Cartoon image (AI-generated by the authors using ChatGPT/DALL·E, 2025).
Figure 2. Image Target. Cartoon image (AI-generated by the authors using ChatGPT/DALL·E, 2025).
Engproc 107 00082 g002
Figure 3. Dominant Color Gradient Result.
Figure 3. Dominant Color Gradient Result.
Engproc 107 00082 g003
Figure 4. Output of the proposed system using the input image (Figure 1) and target image (Figure 2).
Figure 4. Output of the proposed system using the input image (Figure 1) and target image (Figure 2).
Engproc 107 00082 g004
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.

Share and Cite

MDPI and ACS Style

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

AMA Style

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 Style

Sujjada, 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 Style

Sujjada, 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

Article Metrics

Back to TopTop