Creating a Color Palette from an Image

· coding · Source ↗

TLDR

  • Four-iteration palette extractor in Spectrimage uses K-means++ in Oklab with chromatic weighting, phantom guards, and mass-based slot allocation to output five human-feeling swatches.

Key Takeaways

  • Switched from HSL to OKLCH/Oklab: chroma is Euclidean distance from the achromatic axis, avoiding HSL saturation blowup near near-black pixels.
  • K=14 overshoot merges down to five swatches; higher K surfaces chromatic accents that K=10 missed in near-grayscale images like the bicycle test case.
  • Merge step weights the chromatic (a, b) plane 2x over lightness, preventing closest-pair logic from collapsing two reds before it touches a red and a green.
  • Phantom guard drops clusters below 2.5% pixel mass and centroid chroma below 0.05, eliminating gray-pocket phantoms before forced merge passes run.
  • Gray clusters (centroid chroma < 0.03) use the closest-to-centroid pixel as swatch; chromatic clusters use the highest-chroma pixel, biasing toward vivid representation.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN