Engineering Human-Like Color Palettes with OKLCH and K-Means
Article: PositiveCommunity: Very PositiveConsensus

The author describes the development of an algorithm that extracts human-like color palettes from photographs using the OKLCH color space. By iteratively refining K-means clustering with weighted distance merging and structural filters, the system captures both dominant masses and vibrant accents. The final result is a robust tool that prioritizes the 'feeling' of an image over raw pixel averages.
Key Points
- Transitioning from HSL to the OKLCH color space provided a more accurate distance-based measure of chroma, especially near black.
- Increasing the initial cluster count to K=14 allowed the algorithm to identify small but visually important color accents that were previously overwhelmed by dominant backgrounds.
- Weighting the chromatic plane (hue and chroma) twice as much as lightness during the merge phase better aligns the algorithm with human perception of color similarity.
- Structural passes like the 'phantom guard' and mass-based slot allocation prevent the palette from being cluttered by insignificant outliers or redundant neutral tones.
Sentiment
The community is overwhelmingly enthusiastic about the work, with praise for both the technical approach and the quality of results. The only counterpoint is that AI models may eventually make this type of procedural work unnecessary, but even that commenter acknowledges the current technique's merit.
In Agreement
- The palette extraction quality is outstanding — possibly the best color palette generator one commenter has seen, and the problem is genuinely hard based on industry experience.
- RGB is ineffective for color palette extraction; perceptually uniform color spaces like LAB and OKLCH combined with K-means clustering produce far better results.
- The iterative development approach and attention to edge cases (phantom clusters, achromatic vs chromatic balance) demonstrates real craftsmanship.
Opposed
- AI image models like Google's Nano Banana 2 can extract reasonable color palettes with a simple prompt, suggesting procedural approaches may become obsolete per the 'bitter lesson'.
- The algorithm ignores spatial pixel position entirely — incorporating where pixels are located in the image could improve phantom cluster detection, since real objects form connected regions while noise is scattered.