Skip to content

Perceptual color clustering algorithm using Delta E 2000 and hierarchical merging. Groups colors based on human vision similarity through multi-level LAB/HSL analysis.

Notifications You must be signed in to change notification settings

Lakshya0257/Color-clustering

Repository files navigation

Color Clustering Algorithm

A perceptual color clustering system that groups colors based on human vision similarity.

image

Overview

This algorithm implements a multi-level hierarchical clustering approach to group colors in a way that matches human color perception. It uses the LAB color space and Delta E 2000 metric to measure color differences as perceived by the human eye.

Algorithm Breakdown

1. Dynamic Clustering (Level 1)

The initial clustering stage groups colors based on strict perceptual similarity:

  • Uses Delta E 2000 distance metric in LAB color space
  • Colors are added to a cluster only if they're perceptually similar to ALL colors in that cluster
  • Configurable threshold (typically 1.5-20.5) determines the maximum acceptable color difference
  • Output: Initial clusters where colors are nearly indistinguishable to human eye

2. Hierarchical Merging (Level 2)

Two-pass similarity-based merging that considers color properties:

  • Pass 1: Uses colorMatrix to categorize colors by lightness and saturation

    • Categories: BLACK, WHITE, DARKEST_GREY, DARK_GREY, MEDIUM_GREY, LIGHT_GREY, DARK_COLOR, MEDIUM_COLOR, LIGHT_COLOR
    • Merges clusters based on HSL similarity (hue difference < 27°)
    • Different thresholds for same vs. different color categories
  • Pass 2: Uses colorMatrixLevel3 with stricter gray categorization

    • Further consolidates clusters of similar visual characteristics
    • Helps merge dark colors and grays more aggressively

3. Centroid-Based Merging (Final)

Final merging stage using predefined color centroids:

  • Maps each color to nearest centroid from 160+ predefined color references
  • Groups centroids into 15 color families (Red, Green, Blue, Yellow, Orange, Purple, Brown, Pink, Gray, Black, White, Cyan, Magenta, Beige)
  • Merges clusters if >83% of colors belong to same color family
  • Ensures semantically meaningful color groups

Key Features

  • Perceptual Accuracy: Uses CIEDE2000, the industry standard for color difference
  • Context-Aware: Different merging strategies for light vs. dark colors
  • Hue Preservation: Prevents merging of colors with different hues (>27° difference)
  • Adaptive Thresholds: Adjusts strictness based on color lightness and saturation
  • Sorted Output: Colors within each cluster sorted by lightness (light to dark)

Color Space Conversions

  • RGB → XYZ → LAB (for Delta E 2000 calculations)
  • RGB → HSL (for hue-based filtering and categorization)
  • Uses CIE 1964 10° Standard Observer with D65 illuminant

Use Cases

  • Color palette extraction from images
  • Reducing color redundancy in design systems
  • Identifying dominant colors in datasets
  • Color quantization for compression
  • Perceptual color matching

Running the Demo

npm install
npm run dev

Open http://localhost:3000 to see the interactive visualization.

  • Mergable Colors: Initial clusters of perceptually identical colors
  • Final Clusters: Hierarchically grouped color families

Configurable Parameters:

  • Initial clustering threshold (controls perceptual similarity)
  • Similarity thresholds for hierarchical merging
  • Factor weights for cluster evaluation
  • Color family grouping rules

Detailed Documentation

For in-depth technical documentation, implementation details, and iteration notes:

View Full Documentation

License

MIT

About

Perceptual color clustering algorithm using Delta E 2000 and hierarchical merging. Groups colors based on human vision similarity through multi-level LAB/HSL analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages