Smart Cluster Selection for CIELAB Color Segmentation

From Psych 221 Image Systems Engineering
Jump to navigation Jump to search

Introduction

Image segmentation is a fundamental step in many computer vision applications because it allows algorithms to separate meaningful regions, identify objects, and reduce the complexity of visual scenes. Color is one of the most informative cues for distinguishing visual elements, which is why color-based segmentation methods are commonly used. In particular, clustering techniques group pixels that have similar color characteristics, making them effective for isolating regions with shared appearance.

Color-based segmentation is especially important in applications such as remote sensing, where large images often contain regions like vegetation, water, and urban areas that are best distinguished by color. Accurate segmentation in these settings supports tasks such as land cover analysis, environmental monitoring, and change detection, making efficient color segmentation a practical requirement.

A major challenge in color-based segmentation is determining the appropriate number of color clusters for a given image. If too few clusters are chosen, under-segmentation occurs and important details may be merged. If too many clusters are used, over-segmentation can occur, where noise or small variations form meaningless regions. Common techniques such as the Elbow Method and the Gap Statistic estimate the number of clusters by repeatedly running clustering algorithms like K-Means with different values of k. While effective, these methods are computationally expensive for high-resolution images or large datasets and are often unsuitable for real-time use.

This project proposes an alternative approach that estimates the ideal number of color clusters directly from the statistical properties of the image. By analyzing lightness variation, chromatic distributions, and color histograms in the CIELAB color space, the method aims to infer the number of meaningful color groups without testing many cluster values, resulting in a faster and more scalable solution.

Background

Color-based image segmentation is widely used in computer vision because color provides a strong and intuitive cue for separating different regions in an image. Many real-world images contain objects or areas that are more easily distinguished by color than by shape or texture, especially in scenes with complex structure or uneven lighting. By grouping pixels with similar color properties, segmentation methods can reduce image complexity and make later processing steps more efficient.

To make color comparisons meaningful, pixel values are often represented in a perceptual color space rather than directly in RGB. The CIELAB color space is commonly used because it separates lightness from chromatic information, allowing brightness changes to be handled independently from color differences. This is important in practical settings where illumination varies across the image. In addition, CIELAB is approximately perceptually uniform, meaning that distances in the space align reasonably well with how humans perceive color differences. For this reason, simple distance measures in CIELAB are effective for clustering and segmentation tasks.

Many existing segmentation methods rely on statistical information derived from color distributions. Techniques such as K-Means, Mean Shift, and Gaussian Mixture Models group pixels based on similarity, often using histogram information to capture how colors are distributed across an image. Color histograms, in particular, provide a compact summary of lightness and chromatic variation. Peaks in these histograms often correspond to dominant colors or distinct regions, making histogram structure a useful indicator of image complexity.

A key challenge in clustering-based segmentation is selecting the number of clusters. Traditional approaches such as the Elbow Method and the Gap Statistic estimate this number by repeatedly running clustering algorithms with different settings and comparing the results. While these methods are well established, their reliance on multiple clustering runs makes them computationally expensive, especially for high-resolution images or large collections of data.

The ideas behind perceptual color spaces, histogram analysis, and cluster estimation motivate the approach taken in this project. Instead of repeatedly applying clustering algorithms, this work explores whether the number of meaningful color regions can be inferred directly from image statistics in the CIELAB space. By analyzing lightness variation, chromatic spread, and histogram structure, the proposed method aims to estimate the appropriate number of color clusters efficiently, reducing computation while still supporting reliable image segmentation.

Methods

Proposed Method

The proposed method consists of three main stages. First, the input image is converted from the three-channel RGB color space to the CIELAB (Lab*) color space. Separate histograms are then extracted for the L, a, and b channels. Second, two statistical parameters are computed from each histogram: the standard deviation and the number of local maxima. These values describe the distribution and structure of lightness and color information in the image. Finally, the optimal number of color clusters is estimated using the CIELAB Color Segment Estimation (CCSE) function, defined as:

k=ln(σLnL)max(na,nb)+min(na,nb)

In this equation, σL denotes the standard deviation of the L-channel histogram, while nL, na, and nb represent the number of local maxima detected in the L, a, and b histograms, respectively. The term max(na,nb) selects the channel with the strongest chromatic variation, while min(na,nb) represents the weaker chromatic channel. A complete overview of the method is illustrated in the processing pipeline shown in Figure 3. It should be noted that this method requires input images to be in standard three-channel RGB format.

Color Histogram

Color information in an image can be described using several types of descriptors, such as color histograms, color correlograms, color coherence vectors, and color moments. Among these options, the color histogram is one of the most commonly used representations because it is simple to compute and effective at capturing overall color content, especially when an image has a distinct color distribution compared to others in a dataset.

In the proposed method, information is extracted from the L, a, and b histograms by analyzing their standard deviations and the number of local maxima. These measurements describe important properties of the image and provide the motivation for the design of the CCSE function:

  • Lightness distribution: The standard deviation of the L-channel histogram indicates the range of lightness values in the image. A larger standard deviation corresponds to a wider spread of brightness levels, while a smaller value suggests more uniform lighting.
  • Color distribution: The standard deviations of the a and b histograms reflect the diversity of chromatic content. Higher values indicate a broader range of colors, whereas lower values suggest limited color variation.
  • Peak separability: The number of local maxima in the L, a, and b histograms indicates how well different lightness and color levels are separated. More local maxima imply clearly distinguishable color or intensity regions, while fewer maxima suggest more clustered values.
  • Image complexity: Taken together, the standard deviations and local maxima across all three channels provide an estimate of overall image complexity. Images with larger histogram spreads and more peaks are considered more complex, while images with fewer peaks and narrower distributions are simpler.

Overall, histogram analysis offers a compact yet informative description of an image’s lightness and color structure, which is valuable for segmentation and object recognition tasks.

CCSE Function

The term ln(σLnL) computes the logarithm of the ratio between the standard deviation of the L-channel histogram and the number of its local maxima. This ratio reflects the balance between the spread of lightness values and the separability of different lightness levels in the image. Applying the logarithm helps normalize the scale of the values and reduces sensitivity to extreme cases. The floor operation ensures that the resulting estimate of the number of clusters remains an integer. This formulation also prevents the estimated number of clusters from becoming too small when an image contains colors with very similar hues and limited lightness variation.

Multiplying this term by max(na,nb) emphasizes the chromatic channel with the greater number of distinct peaks, which typically corresponds to the dominant source of color variation in the image. Using only the weaker chromatic channel could lead to an underestimation of the required number of color segments.

Finally, adding min(na,nb) ensures that information from the less dominant chromatic channel is still taken into account. While the channel with stronger variation plays a more important role, incorporating the weaker channel leads to a more balanced and accurate estimation of the number of color clusters.

Time Complexity

The time complexity of the function is determined by analyzing each of its main steps. Since the color histograms contain at most 256 bins, operations such as finding local maxima can be treated as constant time. Assigning the image variable takes constant time, while converting the image from RGB to CIELAB requires linear time with respect to the total number of pixels, denoted by N. Histogram computation also has linear time complexity because each pixel contributes once. Peak detection remains constant time due to the fixed histogram size. The loop used in the function has a worst-case time complexity of O(N), and the final computation used to estimate the number of clusters takes constant time. Overall, the operations that depend on image size scale linearly with the number of pixels. Therefore, the total time complexity of the function is O(N), where N is the number of pixels in the image.

Results

Visual Validation

The first part of the evaluation focuses on visual validation, which allows us to directly compare the segmentation results produced by the CCSE algorithm with those from the Elbow Method and the Gap Statistic Method. To ensure a fair comparison, all methods are tested under the same conditions. Since the Elbow and Gap methods require evaluating a range of cluster values, we set a maximum number of clusters of 𝐾max = 20 for all images.

After estimating the optimal number of clusters using each method, the images are segmented accordingly and visually inspected. The comparison focuses on how well each method captures dominant color regions, object boundaries, and overall segmentation smoothness. The results show that the segmentations produced by CCSE are visually very similar to those obtained using the Elbow and Gap methods. This indicates that CCSE successfully captures the main color structures of the images.

Overall, this visual validation demonstrates that CCSE can achieve segmentation quality comparable to established methods, while avoiding the repeated clustering steps required by the Elbow and Gap approaches.

Quantitative Validation

Quantitative validation is performed using Color Reconstruction Error-based Segmentation Evaluation (CRESE). This metric evaluates how accurately a segmented image reconstructs the original image in terms of color. It computes the sum of color differences between each pixel’s original color and the average color of the cluster to which the pixel is assigned. A lower reconstruction error indicates better segmentation performance and a more accurate estimate of the number of color clusters.

Let OH×W×3 denote the original image, and let SH×W×3 denote the segmented image, where each pixel is replaced by the average color of its assigned cluster. Let C=c1,c2,,cn be the set of unique cluster colors in S, where n is the number of clusters. For each cluster color ci, a binary mask Mi0,1H×W is defined to indicate pixel membership.

The total color reconstruction error E is computed as follows:

E=i=1nh=1Hw=1WMi(h,w)O(h,w)ci2

The ||*|| shows the Euclidean distance between color vectors. In this evaluation, the color reconstruction error is computed using the Euclidean distance between color vectors in the CIELAB color space. Both the original image O and the cluster representative colors ci are first converted from RGB to CIELAB before the distance is computed. This choice is motivated by the perceptual properties of the CIELAB color space, which is designed so that Euclidean distances correspond approximately to perceived color differences. As a result, Euclidean distance in CIELAB provides a meaningful and interpretable measure of how well the segmented image preserves the original colors.

Although perceptual color difference metrics such as ΔE are commonly used for precise color comparison, Euclidean distance in CIELAB offers a computationally efficient alternative while remaining perceptually relevant. Since CRESE is used to compare relative segmentation performance across methods rather than to measure absolute perceptual color error, this simplified distance metric is sufficient for evaluation purposes. In contrast, computing reconstruction error directly in RGB space would be less appropriate, as Euclidean distances in RGB do not correspond well to human color perception and are sensitive to illumination variations.

To enable comparison across images of different sizes, the error is normalized and expressed as a percentage:

Enormalized=EHW2553×100

During experimentation, contrast enhancement was observed to increase the estimated number of clusters. Since contrast enhancement has constant-time complexity, it does not affect the computational cost of the CRESE evaluation. Using this metric, validation curves of normalized reconstruction error versus the number of clusters k are generated for both original and contrast-enhanced images.

Efficiency Validation

This section evaluates the computation time of the CCSE algorithm and compares it with the Elbow Method and the Gap Statistic Method in the context of image segmentation. While earlier sections focused on segmentation accuracy, the goal here is to understand how efficiently each method performs as image size increases.

A high resolution beach image with a size of 3840 × 2160 pixels is used as the test image. The image is not contrast enhanced so that computation time is affected only by image size and not by additional preprocessing. To analyze scalability, resized versions of the image are created while preserving the original aspect ratio. The image is scaled to 10%, 25%, 33%, 50%, and 75% of its original dimensions, resulting in a range of images with different pixel counts.

To ensure a fair comparison, the maximum number of clusters is fixed at Kmax=20 for both the Elbow Method and the Gap Statistic Method. For each resized image, the time required by each algorithm to estimate the optimal number of clusters is measured. These measurements allow us to observe how computation time changes as image resolution increases.

By comparing the computation times across all image sizes, we can evaluate the efficiency and scalability of each method. This analysis helps determine which approach is more suitable for real world applications where image sizes may vary significantly. The results also highlight the ability of the CCSE algorithm to handle larger images efficiently while still producing reliable cluster estimates.

Sensitivity Validation

Sensitivity analysis is used to evaluate how stable each clustering method is when its input parameters change. A method that is less sensitive to parameter variation is considered more robust because it produces more consistent results under different settings.

In this study, sensitivity is evaluated for all three methods. For the Elbow Method and the Gap Statistic Method, sensitivity is tested by changing the maximum number of clusters, Kmax. For the CCSE algorithm, sensitivity is examined by varying the distance parameter D, which controls how histogram peaks are grouped when estimating the number of clusters.

To ensure a fair comparison, the same parameter range is used for all methods. The value of D for CCSE is set equal to Kmax for the Elbow and Gap methods. Both parameters are varied from 5 to 40, using an increment of 5. For each parameter value, the estimated number of clusters is recorded and compared.

The Gap Statistic Method shows a nearly linear increase in the estimated number of clusters as Kmax increases. This behavior indicates a high sensitivity to the chosen maximum value, meaning the estimated result depends strongly on the input parameter.

The Elbow Method shows a non linear trend and is slightly less sensitive than the Gap Statistic Method. However, the estimated number of clusters still changes noticeably as Kmax increases, which suggests that the method remains dependent on the selected parameter range.

In contrast, the CCSE algorithm produces more stable estimates as the distance parameter D increases. While the estimated number of clusters decreases gradually, the change is smoother and more controlled compared to the other methods. This indicates lower sensitivity to parameter variation.

Overall, the CCSE algorithm demonstrates the highest robustness among the three methods. Its reduced sensitivity to parameter changes allows it to produce more consistent cluster estimates across a wide range of settings, making it more reliable for practical image segmentation tasks.

Conclusion

From the results presented above, it can be concluded that the proposed CCSE algorithm performs well across several important aspects of image segmentation, including segmentation quality, computation time, and robustness. Visual inspection shows that the segmented images produced using CCSE are similar to those generated by the Elbow Method and the Gap Statistic, indicating that CCSE is able to capture the main color structure of the images.

Quantitative evaluation using the CRESE metric further supports these observations. For both original and contrast-enhanced images, the reconstruction errors produced by CCSE are comparable to those of the other methods. This shows that CCSE can estimate a reasonable number of color clusters even when image contrast changes.

In terms of efficiency, CCSE clearly outperforms the Elbow and Gap Statistic methods. Its computation time increases very little as image size grows, making it suitable for high-resolution images and large datasets. In addition, CCSE shows stable behavior across different parameter settings, which indicates good robustness.

Overall, the CCSE algorithm provides a practical and reliable approach for estimating the number of color clusters in image segmentation, offering a good balance between accuracy, speed, and stability.

References

[1] Kim, D. W., S. J. Jeong, W. S. Lee, H. Yun, and Y. S. Chung. “Growth Monitoring of Field-Grown Onion and Garlic by CIE L*a*b* Color Space and Region-Based Crop Segmentation of UAV RGB Images.” Precision Agriculture, 2023, Springer.

[2] Abdelsadek, D. A., M. N. Al-Berry, H. M. Ebied, et al. “Impact of Using Different Color Spaces on Image Segmentation.” Proceedings of the International Conference on Advanced Computing, 2022, Springer.

[3] Permadi, V. A., S. P. Tahalea, and R. P. Agusdin. “K-Means and Elbow Method for Cluster Analysis of Elementary School Data.” Progres Pendidikan, 2023.

[4] Herdiana, I., M. A. Kamal, and M. N. Estri. “A More Precise Elbow Method for Optimum K-Means Clustering.” arXiv, arXiv:2502.00851, 2025.

[5] Khan, I. K., H. Daud, N. Zainuddin, et al. “Standardizing Reference Data in Gap Statistic for Selection of Optimal Number of Clusters in K-Means Algorithm.” Alexandria Engineering Journal, 2025, Elsevier.

[6] Cinko, U. O., and B. Becerir. “Computing Characteristics of Color Difference Formulas for Regular Coordinate Changes in CIELAB Color Space.” Textile Research Journal, 2025.

[7] Jain, Y., V. Saxena, and S. Mittal. “Ensembling Deep Learning and CIELAB Color Space Model for Fire Detection from UAV Images.” Proceedings of the Second International Conference on Artificial Intelligence Applications, 2022, ACM.

Appendix 1

link to code: https://drive.google.com/drive/folders/1kJ1jRgtYwjPT1HOiSKBag3t2gvJKGu8J?usp=drive_link