Color Palette Extractor

Extract dominant colors from any image using GPU-accelerated K-Means clustering. Runs entirely in your browser. Files stay on your device.

Colors (K)6
Drag & Drop an image hereor click the upload button
Extracted Palette
Awaiting image...

Demystifying K-Means Clustering

Have you ever wondered how computers look at millions of pixels and decide which colors belong in a palette? The core idea is a mathematical algorithm called K-Means. Here is how it groups similar colors into a smaller set.

Interactive visualization of K-Means clustering algorithm applied to image color extraction
Live Process1. Initialization

This visualizer maps 400 sample pixels from your image onto a 2D grid based entirely on their Red (horizontal) and Green (vertical) values to demonstrate the algorithm. Scroll down to see the math in action.

1

Initialization (Choosing 'K')

Imagine you have a massive pile of unorganized colored beads, and you want to sort them into specific jars based on their color similarity. Doing this one by one would take a long time.

First, you have to decide exactly how many final colors you want in your palette. This number is called K. In our visualizer on the left, we randomly drop K "Centroids" (the large outlined circles) directly into the messy data. Think of these Centroids as team captains looking to recruit members.

2

The Assignment Step (Grouping)

Now the sorting begins. Every single tiny pixel looks at all the available Centroids on the board and asks: "Which captain am I physically closest to?"

It measures the distance (like using a ruler across a graph) and "snaps" to the Centroid nearest to its own color. Once every pixel has picked a side, the data is officially grouped into rough, initial clusters. Notice how each point on the left is now outlined with its captain's color.

3

The Update Step (Finding the Center)

The initial random guesses for the captains' positions were only a starting point. Now that the captains have their teams assigned, they look at all the pixels in their group and calculate the average (the mean) position of everyone.

The Centroid then physically moves to stand exactly in the true middle of its team. By moving to this new center, the Centroid now accurately represents the average color of all those pixels combined.

4

The Iteration Loop

The assignment changes here. Because the Centroids moved in Step 3, the boundaries changed. A pixel that previously belonged to the Blue captain might suddenly realize the Red captain has moved much closer to it!

To fix this, the computer creates an Iteration Loop. It continuously repeats Step 2 (Assign) and Step 3 (Update) over and over. Watch the visualizer: the points change allegiances, the centers shift, and the clusters slowly refine themselves in real-time.

5

Convergence (The Final Result)

The algorithm loops until the groups stop changing. Eventually, the Centroids settle near the center of their color groups, and no pixels need to change teams anymore.

When this happens, we say the algorithm has converged. The final positions of these Centroids represent the dominant colors of your image. We extract those colors, and that becomes your final generated palette.

How to Extract Colors from an Image

Drop any image above and choose how many colors to extract (1 to 12). The tool analyzes every pixel using K-Means clustering, identifies the dominant color groups, and displays them as a palette. Copy individual HEX or RGB values with one click. No upload. No account.

Designers use this to pull color palettes from photographs, brand assets, and reference images. It is also useful for creating cohesive social media themes, matching paint colors from a photo, and generating accessible color schemes from existing designs.

How GPU-Accelerated K-Means Clustering Works

K-Means is a clustering algorithm that groups data points (pixels) into K clusters based on color similarity. Each pixel is assigned to the nearest cluster center, then each center is recalculated as the average of its assigned pixels. This repeats until the centers stabilize.

Running K-Means on a million pixels in JavaScript would be slow. This tool offloads the computation to your GPU via WebGL2 shaders. The assignment and averaging steps run as fragment shader passes, so large images stay responsive.

Why Use a Browser-Based Color Palette Generator?

Desktop tools like Adobe Color and Figma plugins extract palettes, but they require an account or a specific application. Cloud-based palette extractors upload your image to their servers. This tool runs the full K-Means algorithm locally on your GPU. Your images stay on your device.

After extracting colors, you can compress your image for web use or convert it to WebP for smaller file sizes. For professional video and media workflows, explore Velocaption. Browse all free tools on the tools page.