Extract the dominant colors from any image as a hex palette. Upload a photo, logo, illustration, or screenshot; the tool downsamples it, feeds the pixels to a median-cut quantizer, and outputs a palette of 3 to 10 colors. Everything runs in your browser — the image is never uploaded to a server.
This tool is useful for building moodboards from reference photos, reverse-engineering a brand color scheme from a logo, picking a color palette for a website from a hero image, or just satisfying curiosity about what colors an image actually uses. Click any swatch in the result to copy its hex code, or feed one into the harmony visualizer to build a full scheme around it.
How median cut works
The algorithm takes an array of RGB pixels and a target palette size, then partitions the pixels into that many groups, then averages each group to produce one palette color:
- Find the color channel with the widest spread in the pixel set (the one where
max − minis largest). - Sort the pixels by that channel.
- Split the sorted list at the median into two halves.
- Recurse on each half, reducing the remaining depth.
- When depth reaches zero, each leaf bucket collapses into a single color — the average of all its pixels.
For a target palette of size $n$, the algorithm runs for $\lceil \log_2 n \rceil$ levels of recursion, producing $2^{\lceil \log_2 n \rceil}$ leaf buckets, which are then truncated to the requested size. For 8 colors, that’s 3 levels of splits and exactly 8 leaves.
Median cut is a 1980s algorithm, originally invented by Paul Heckbert for 24-bit to 8-bit color quantization in GIF encoding. It’s not the most sophisticated approach available — k-means clustering can produce slightly better perceptual results on some images — but it’s fast, deterministic, and has none of k-means’ random-seed behavior. Same input produces the same palette every time.
Example: a sunset photograph
A typical sunset photo has a few dominant color zones: the sky gradient (oranges to deep blues), the ground (shadowy dark), and maybe a few specular highlights. Running median cut with size 5 on such an image will usually recover:
- A deep blue from the upper sky
- A warmer orange-red from the lower sky
- A mid-grey from the transition zone
- A near-black from the ground shadows
- A bright highlight color from the setting sun
This is a better-than-average case because the color zones are geometrically separable in RGB space — warm sunset colors and cool sky colors fall on opposite sides of the red/blue axis, so the first median cut splits them cleanly.
Example: a corporate logo
Logos are much easier because they typically use a small number of flat colors with no gradients. Running median cut with size 4 on the Google logo should recover colors close to Google’s brand blue, red, yellow, and green. The result won’t be exact because of anti-aliasing at the letter edges (some pixels are blends of two brand colors and one background), but it’ll be close enough to use as a starting point — paste the extracted hex into the hex/RGB/HSL converter if you want to nudge it toward a specific saturation or lightness.
Example: a complex photograph
A photograph with lots of colors and smooth gradients — a landscape with a river, trees, sky, and sunlight — is a harder case. Median cut with size 8 will produce something usable, but no small palette can fully represent a photo with hundreds of distinguishable colors. The output is a “what does this image feel like” summary, not a faithful reproduction. If you want a larger palette that captures more of the image’s color range, bump the size up — 10 usually gives a good compromise.
Performance notes
The extractor downsamples any uploaded image to a maximum 400-pixel dimension before sampling pixels, then samples roughly 10,000 pixels for the median cut itself. This gives good results for any reasonable input size while keeping extraction time well under a second on typical hardware. Large source images (several megapixels) don’t slow anything down significantly because of the downsampling.
The entire algorithm runs synchronously in the main thread because even the largest sampled pixel set is fast enough not to need a web worker. If you notice a slow response on an unusually large image, it’s most likely the image decoding, not the quantization.
What this tool does not do
It does not offer k-means clustering, octree quantization, or any of the other color-reduction algorithms — just median cut. It does not let you select regions of the image to extract from (the whole image is always used). It does not preserve relative color proportions in the output — every swatch takes equal space regardless of how many pixels it represents in the source image. And it does not cluster by perceptual similarity using CIELAB or OKLCH; the math runs in straight sRGB space, which can occasionally produce buckets that look unusually close together despite being numerically separated.
For all of these, a more elaborate tool or a design app like Adobe Color is the right move. For “show me the dominant colors of this image, fast”, median cut is perfectly fit for purpose.