How to Extract a Color Palette From an Image
A photo of a market stall, a client's logo, a film still you love — each holds a palette. Extracting it is quick. Getting a palette you can actually build a design on takes knowing what the extractor is doing and where it will mislead you.
How extractors choose colours
A 12-megapixel photo can contain hundreds of thousands of distinct colours. Every palette tool reduces them to a handful, and they do it in one of three broad ways:
Counting (histogram)
Round each colour to a coarse grid and keep the most common buckets. Fast and simple, but neighbouring shades of the same sky fill the top five slots and the red jacket never appears.
k-means clustering
Place k centres, assign every pixel to its nearest centre, move each centre to the mean of its pixels, repeat. Good results, but the starting points are random, so the same image can give slightly different palettes on each run.
Median cut
Paul Heckbert's 1982 method: treat the pixels as a box in RGB space and keep splitting the box with the most spread until there are as many boxes as colours you want. Deterministic and fast; the classic version averages each box, which can produce colours that are not in the image.
The Color Palette from Image tool uses a variance-based median cut: it always splits the group whose colours disagree most, at the point that leaves both halves most uniform. On a flat logo that gives back the logo's exact colours rather than blends of them, and the percentage shown beside each swatch is the share of the image it covers.
Why two tools disagree about the same photo
- Averaging. A box containing deep red and orange averages to a red-orange that appears nowhere in the photo. Some tools then snap to the nearest real pixel; some don't.
- Downscaling first. Nearly every tool shrinks the image before analysing it. Fine detail — thin text, a small logo — can vanish before counting begins.
- Dominant versus memorable. Extractors weight by area. A tiny, saturated accent that defines the photo for a human eye may cover 1% of the pixels and lose every vote to the background.
- Colour distance. RGB distance does not match human perception: two greens can be far apart numerically and look alike, while two blues close in RGB look clearly different. Tools that measure in a perceptual space such as CIELAB or OKLab group colours more like you would.
Getting a better palette
- Crop to what you care about. If the wall behind the subject is not part of the mood, crop it out first. This is the single biggest improvement.
- Ask for more colours than you need. Extract 8–10, then choose 4–6. The accent you want often shows up in slot seven.
- Use the eyedropper for exact values. For a logo or a brand mark, pick the pixel directly instead of trusting a cluster average. Avoid edges, where anti-aliasing mixes the colour with its background.
- Remember it is a screen colour. A photo of a printed logo gives you the colour under that light through that camera. For brand work, ask for the official values.
From photo palette to usable UI colours
A palette from a photograph is a mood, not a design system. Photos are full of mid-tones; interfaces need very light and very dark colours for backgrounds and text. A workable approach:
- Pick one extracted colour as the brand or accent colour — buttons, links, highlights.
- Derive near-white and near-dark neutrals by keeping a hint of the palette's hue at very low saturation, instead of pure grey.
- Keep the remaining extracted colours for illustration, charts and tags, used sparingly. A common rule of thumb is roughly 60% neutral, 30% secondary, 10% accent.
Then test contrast. WCAG asks for at least 4.5:1 for normal body text and 3:1 for large text and for UI parts such as button outlines and focus rings. Mid-tone photo colours often fail with both white and black text — the swatches in the palette tool show which of the two reads better, and the contrast checker gives the exact ratio for any pair.
Finally, put the palette where the code can use it:
:root {
--color-accent: #c2410c; /* from the photo */
--color-surface: #fdf8f3; /* near-white, warm */
--color-ink: #2a1d14; /* near-black, warm */
--color-muted: #a8a29e;
}
.button { background: var(--color-accent); color: #fff; } Pull a color palette from any photo — free, in your browser