Palette from Image

Pull the main colours out of any photo, logo or artwork with median cut or k-means, see how much of the image each colour covers and where it is, and copy the palette as CSS or JSON.

Extractor Color & Design Updated Oct 3, 2026
Learn how this works
How to Use
  1. Drop an image, choose a file, or try one of the sample scenes. Almost any format works, including HEIC, TIFF and camera RAW.
  2. Choose how many colours to extract and the method: Median cut (fast, covers the range) or K-means (refined to match how we see colour).
  3. Tick Ignore near-white and near-black to skip plain backgrounds and shadows.
  4. The bar shows how much of the image each colour covers. Click a swatch to highlight where it appears and copy its hex.
  5. Copy the whole palette as CSS custom properties, SCSS, JSON, Tailwind colours or a hex list.
Input
6
Sample images
Palette
Drop an image or pick a sample to see its colours.
Colours
—
Pixels sampled
—
Top colour
—
Fit (avg ΔE)
—

Worked Example

Extract 3 colours from the flag of France (the “Flag of France” sample): blue #002395, white #FFFFFF and red #ED2939 in three equal bands.

Median cut alone starts with all 17,120 sampled pixels in one group. The widest spread is in red (blue has 0, red 237, white 255), so it sorts by red and splits at the middle pixel — which falls inside the red band, cutting it in two. The next split separates blue from the first half of the red. The result is #002395 (correct), a pink #F9B9BF that mixes white with half the red, and a dark #A02757. The fit readout is 11.2: a poor match.

K-means then moves each colour to the OKLab average of the pixels nearest to it. The red pixels are nearer the dark red centre than the pink one, so they move over, and within two rounds the colours settle on exactly #002395, #FFFFFF and #ED2939 at about a third of the image each. Every pixel now matches its colour, so the fit is 0.0. That is why K-means is the default.

Show Work

Load an image above to see how its palette is found.

Formulas

Sample
longest side ≤ 160 px
Pixels under 50% opacity are skipped
Median cut
split widest group at its median
Along its longest R, G or B axis, until n groups
K-means step
ck = mean of pixels nearest ck
Distance in OKLab; up to 12 rounds
Share
pixels in group ÷ pixels sampled
Fit
mean ΔEOK(pixel, its colour)
OKLab distance × 100

Fitting Millions of Colours into a Few

Paul Heckbert described median cut in 1982, when most displays could show only 256 colours and every full-colour image had to be reduced to a palette. It remains the basis of many GIF encoders and colour pickers. K-means clustering, named by James MacQueen in 1967 and based on Stuart Lloyd’s 1957 algorithm, refines such a palette by repeatedly moving each colour to the centre of the pixels it represents.

Running k-means in a perceptual space such as OKLab rather than raw RGB makes “closest colour” mean what it does to a person, which keeps palettes from spending several colours on shades we can barely tell apart.

About This Tool

This tool extracts 2 to 16 colours from an image with median cut, optionally refined by k-means in OKLab, and reports each colour’s share of the image and how faithfully the palette fits it. Clicking a colour highlights the pixels it represents. Plain near-white and near-black backgrounds can be ignored.

Images are read with the same engine as the Universal Image Converter, so photos, screenshots, HEIC, TIFF and many older formats all work. Everything runs in your browser and nothing is uploaded.

Related tools: Color Eyedropper, Color Palette Generator, and Universal Color Converter.

Frequently Asked Questions

How does the tool find the main colours?

It shrinks the image to at most 160 px across (about 25,000 pixels), then median cut repeatedly splits the group of pixels with the widest colour range in half along its longest axis until there are as many groups as colours requested. Each group’s average is a palette colour, and its size is that colour’s share of the image.

What does K-means add?

It starts from the median-cut colours and repeatedly moves each one to the average of the pixels nearest to it, measuring distance in OKLab so that “nearest” matches what we see. That usually gives colours that sit right in the middle of the real shades of the image, and lowers the average error shown in the readout.

What is the “fit” readout?

The average colour difference (ΔE, in OKLab × 100) between each pixel and the palette colour it was assigned to. Lower means the palette represents the image more faithfully: under about 5 the palette captures it well; above 10 the image has more variety than the number of colours allows.

Why are some colours I can see missing?

Small areas make small groups, which get merged when there are only a few colours to go round. A bright logo on a large photo may need 10–16 colours before it gets its own swatch. Ignoring near-white and near-black also frees up colours that would be spent on backgrounds.

Is my image uploaded?

No. The image is decoded and analysed in your browser; nothing is sent to a server.

How do I use the Palette from Image?

Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Do I need to install or sign up for anything?

Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.

Is my information private?

Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.

Common Use Cases

Brand and theme colours

Take a hero photo and get 5 colours that match it, with shares to show which should dominate (for example 60% background, 30% main, 10% accent).

Matching a product photo

Pull the exact colour of a product from its photo for a button or label, then check it with the Contrast Checker.

Moodboards and art

Record the colour story of a painting or reference image for a style guide.

Checking a logo

Confirm a flat logo really uses its 3 brand colours: a flag such as France comes out as exactly three colours at about a third each.

Last updated: