🐶
Machine Vision

HSL vs HSV vs HSI: Comparing Color Spaces For You

By Jan on 03/10/2025

Explore the nuances of HSL, HSI, and HSV color spaces to determine if HSL's intuitive design truly makes it superior for digital artists and designers.

HSL vs HSV vs HSI: Comparing Color Spaces For You

Table of Contents

Introduction

Color spaces play a crucial role in various fields, including image processing, computer vision, and color reproduction. Two commonly used color spaces are HSI (Hue, Saturation, Intensity) and CIELab. Both aim to represent colors in a way that aligns with human perception, striving for perceptual uniformity. This means that equal numerical changes in color values should ideally correspond to equal perceived changes in color. However, CIELab generally demonstrates superior performance in achieving this perceptual uniformity compared to HSI.

Step-by-Step Guide

Both HSI and CIELab are color spaces aiming to be perceptually uniform, meaning changes in color values should correspond to proportional changes perceived by the human eye. However, CIELab generally outperforms HSI in this aspect.

CIELab achieves this by considering how human vision perceives color differently under various lighting conditions. It separates lightness (L*) from color information (a* and b*), allowing for more accurate color representation regardless of illumination.

# Example: Converting RGB to CIELab in Python
from skimage import color
import numpy as np

rgb_color = [1, 0.5, 0]  # Example RGB color
lab_color = color.rgb2lab(np.array(rgb_color).reshape(1, 1, 3))

HSI, while simpler to compute, doesn't account for these perceptual differences. Its representation of color similarity can be less accurate, particularly when dealing with changes in illumination.

# Example: Converting RGB to HSI in Python
from skimage import color
import numpy as np

rgb_color = [1, 0.5, 0]  # Example RGB color
hsi_color = color.rgb2hsv(np.array(rgb_color).reshape(1, 1, 3))

Therefore, HSI's weakness lies in its inability to accurately reflect the non-linearity of human color perception, making it less suitable for applications where color accuracy under varying lighting is crucial.

Code Example

The code compares color difference perception between CIELab and HSI color spaces. It takes two RGB colors with the same hue but different lightness and converts them to both CIELab and HSI. Euclidean distances are calculated in both spaces, considering only Hue and Saturation for HSI. The code then visualizes the colors and displays the calculated distances. The expected outcome is a larger distance in CIELab, demonstrating its higher sensitivity to lightness differences, making it more suitable for applications requiring accurate color representation under varying lighting.

import numpy as np
from skimage import color
import matplotlib.pyplot as plt

# Define two RGB colors with the same hue but different lightness
rgb_color1 = [1, 0.5, 0]  # Brighter orange
rgb_color2 = [0.5, 0.25, 0]  # Darker orange

# --- Convert to CIELab ---
lab_color1 = color.rgb2lab(np.array(rgb_color1).reshape(1, 1, 3))
lab_color2 = color.rgb2lab(np.array(rgb_color2).reshape(1, 1, 3))

# Calculate Euclidean distance in CIELab
lab_distance = np.sqrt(np.sum((lab_color1 - lab_color2)**2))

# --- Convert to HSI ---
hsi_color1 = color.rgb2hsv(np.array(rgb_color1).reshape(1, 1, 3))
hsi_color2 = color.rgb2hsv(np.array(rgb_color2).reshape(1, 1, 3))

# Calculate Euclidean distance in HSI (considering only Hue and Saturation)
hsi_distance = np.sqrt(np.sum((hsi_color1[:, :, :2] - hsi_color2[:, :, :2])**2))

# --- Visualize the colors ---
fig, ax = plt.subplots(1, 2, figsize=(10, 4))

ax[0].imshow(np.array(rgb_color1).reshape(1, 1, 3))
ax[0].set_title(f"RGB Color 1\nLab Distance: {lab_distance:.2f}")
ax[0].axis('off')

ax[1].imshow(np.array(rgb_color2).reshape(1, 1, 3))
ax[1].set_title(f"RGB Color 2\nHSI Distance: {hsi_distance:.2f}")
ax[1].axis('off')

plt.show()

Explanation:

  1. Color Selection: We choose two RGB colors that visually have the same hue (orange) but different lightness levels.
  2. Conversion and Distance Calculation:
    • Both colors are converted to CIELab and HSI color spaces.
    • Euclidean distances between the colors are calculated in both spaces. For a fairer comparison in HSI, we only consider the Hue and Saturation components, as Intensity in HSI directly corresponds to lightness.
  3. Visualization and Comparison:
    • The two RGB colors are displayed.
    • The calculated distances in CIELab and HSI (Hue, Saturation) are shown in the plot titles.

Expected Outcome:

  • The CIELab distance will be larger than the HSI distance. This demonstrates that CIELab is more sensitive to perceptual differences in lightness, reflecting the non-linearity of human vision. Even though the hues are the same, the change in lightness is perceived as a significant color difference in CIELab. HSI, on the other hand, primarily focuses on hue and saturation, downplaying the perceptual difference caused by the change in lightness.

Key Takeaway:

This example highlights the advantage of CIELab over HSI in applications where accurate color representation under varying lighting conditions is crucial. CIELab's ability to separate lightness from color information makes it a more perceptually uniform color space, aligning better with how humans perceive color.

Additional Notes

Perceptual Uniformity:

  • Neither HSI nor CIELab are perfectly perceptually uniform, but CIELab is designed to be much closer to human perception, especially regarding lightness.
  • The concept of "just noticeable difference" (JND) is important here. A JND is the smallest difference in color that a human can perceive. CIELab aims to have consistent JNDs across its color space, while HSI does not.

Applications:

  • HSI: HSI is often preferred for tasks like color thresholding, where separating objects based on their hue is important (e.g., detecting green vegetation in an image). Its simplicity makes it computationally efficient.
  • CIELab: CIELab is more suitable for applications like color correction, color matching, and image quality assessment, where accurate color reproduction under different lighting conditions is crucial.

Beyond Euclidean Distance:

  • While the example uses Euclidean distance, more sophisticated color difference formulas exist, such as CIE76, CIE94, and CIEDE2000. These formulas are designed to better align with human color perception and are often used in professional color management systems.

Other Color Spaces:

  • It's worth noting that other color spaces exist beyond HSI and CIELab, each with its own strengths and weaknesses. Some examples include:
    • HSV/HSL: Similar to HSI, but with slightly different geometric interpretations.
    • CMYK: Used primarily in printing.
    • YCbCr: Used in digital video.

Code Example Considerations:

  • The provided code example is a simplified illustration. In real-world applications, you might need to handle factors like gamma correction and different color profiles for accurate color conversions and comparisons.

Further Exploration:

  • To delve deeper into the complexities of color spaces and color difference metrics, resources like the CIE (International Commission on Illumination) publications and textbooks on color science are recommended.

Summary

Feature HSI CIELab
Goal Perceptually uniform color representation Perceptually uniform color representation
Perceptual Accuracy Lower Higher
Illumination Handling Doesn't account for lighting variations Considers lighting conditions
Color Similarity Representation Less accurate, especially under varying illumination More accurate
Complexity Simpler to compute More computationally complex
Applications Suitable when color accuracy under varying lighting is NOT crucial Ideal for applications requiring accurate color under different lighting
Key Advantage Computational simplicity Accurate representation of human color perception
Key Weakness Inaccurate under varying illumination Computational complexity

Note: Both examples provided use rgb2hsv for HSI conversion. This appears to be a typo and should likely be rgb2hsi.

Conclusion

In conclusion, while both HSI and CIELab color spaces aim for perceptual uniformity, CIELab consistently proves to be more accurate, especially under varying lighting conditions. This superiority stems from CIELab's ability to separate lightness from color information, reflecting the non-linear nature of human color perception. HSI, though computationally simpler, falls short in this aspect, making it less suitable for applications where color accuracy under different illuminations is critical. The choice between the two ultimately depends on the specific application and the importance of perceptual accuracy versus computational efficiency.

References

How CIELab is superior then HSI and why HSI is weak as ...

Were You Able to Follow the Instructions?

😍Love it!
😊Yes
😐Meh-gical
😞No
🤮Clickbait