How K-Means Color Quantization & Dominant Brand Palette Extraction Work
Turning Inspiration Photos & Brand Logos into Cohesive UI Color Systems
Every great brand identity, website theme, or illustration relies on a harmonious set of dominant, secondary, and accent colors. However, a standard 12-megapixel photograph contains hundreds of thousands of subtle pixel variations caused by lighting gradients and camera sensor noise. Our browser-based Color Palette Generator samples your uploaded image onto an offscreen HTML5 Canvas and runs an iterative K-Means clustering color quantization algorithm—grouping visually similar RGB pixels around their nearest cluster centroids and ranking them by pixel coverage percentage. Within milliseconds, you receive clean 6-digit HEX codes, RGB triplets, a ready-to-paste CSS :root variable block, and a downloadable PNG swatch card.
How to Extract a Color Palette from Any Image in 3 Easy Steps
- Upload a Photo or Logo: Drop any JPG, PNG, WebP, or SVG image into the upload zone above (or click Load Sample Image to test immediately).
- Choose Palette Swatch Count: Select 6 Colors, 8 Colors, or 10 Colors at the top to refine primary and accent extraction.
- Copy HEX / CSS or Save PNG Card: Click any individual color swatch to copy its HEX code, copy the full CSS variable snippet, or click Download PNG Palette Card.
3D Euclidean RGB Color Distance Formula + Worked Example
To assign each sampled pixel (R1, G1, B1) to its closest palette centroid (R2, G2, B2), the clustering engine minimizes 3D Euclidean color distance:
Color Distance (ΔERGB) = √[ (R2 − R1)² + (G2 − G1)² + (B2 − B1)² ]
Worked Example: Suppose an image pixel has RGB(35, 102, 232) and two candidate palette centroids are Brand Blue RGB(37, 99, 235) and Slate Dark RGB(15, 23, 42).
Distance to Brand Blue = √[ (37−35)² + (99−102)² + (235−232)² ] = √(4 + 9 + 9) = 4.69.
Distance to Slate Dark = √[ (15−35)² + (23−102)² + (42−232)² ] = 206.74 → The pixel joins the Brand Blue (#2563EB) cluster.
UI Design Color Proportions (60-30-10 Rule) & Palette Roles (16 Guidelines)
Use this UI/UX color system reference chart to apply your extracted image palette cleanly across websites and mobile apps.
| Palette Role / Rule |
Recommended Share |
UI Elements Assigned |
Design Best Practice |
| 60-30-10 Rule: Dominant Neutral |
60% of Viewport |
Page background, cards, whitespace |
Keep light (#F8FAFC) or dark (#0F172A) for readability |
| 60-30-10 Rule: Secondary Brand |
30% of Viewport |
Navigation headers, footers, sidebars, icons |
Supports brand identity without visual fatigue |
| 60-30-10 Rule: Primary Accent |
10% of Viewport |
Primary CTA buttons, active tabs, links, badges |
Highest saturation swatch from your palette |
| Primary Text Contrast |
WCAG AA (≥ 4.5:1) |
Headings & body paragraphs |
Verify readability using our Color Picker tool |
| Border & Divider Tint |
10%–15% Opacity |
Card outlines, table gridlines, input borders |
Subtle neutral tone derived from dominant swatch |
| Hover / Active State Shift |
-8% to -12% Lightness |
Button hover, focused inputs, active pills |
Darken primary accent slightly for tactile feedback |
| Soft Background Tint |
92%–96% Lightness |
Alert callouts, formula boxes, selected rows |
Light pastel tint of your primary brand hue |
| Semantic Success Color |
Green Hue (~145°–160°) |
"Completed", "Verified", savings badges |
Keep distinct from primary action buttons |
| Semantic Warning Color |
Amber Hue (~38°–45°) |
Caution banners, pending status pills |
Pair with dark text for high legibility |
| Semantic Danger / Error |
Red Hue (~0°–10°) |
Validation errors, delete buttons |
Reserve strictly for destructive/error states |
| 6-Color Palette Extraction |
Core Brand Set |
Logos, flat illustrations, minimalist UI |
Captures main hues without noisy midtones |
| 8-Color Palette Extraction |
Balanced Photo Set |
Landscape & product photography themes |
Includes both highlights and shadow tones |
| 10-Color Palette Extraction |
Full Gradient Spectrum |
Complex artwork & editorial moodboards |
Reveals subtle secondary accent shades |
CSS Custom Properties (--var) |
Global Theme Tokens |
:root { --palette-1: #...; } |
Instant paste into Tailwind/CSS stylesheets |
| PNG Palette Swatch Card |
1200 × 420 px Export |
Client brand guidelines & moodboards |
Includes color bars + printed HEX labels |
| Extraction Privacy |
100% Local Canvas |
Zero Server Upload |
Proprietary brand assets stay on your device |
Picking individual pixel colors, checking WCAG contrast ratios, converting SVG vectors to PNG, or generating favicons? Explore our companion tools: