Palette from an Image
The main colors of an image: pick a file and the number of colors. The picture is not uploaded to a server; everything is worked out in your browser.
How it is calculated
The median cut method: all pixels go into one box; the box with the widest color range is cut in half at the median of its widest channel, and so on up to the number wanted.
The color of each box is the average of its pixels and the share is the percentage of pixels. For speed the image is reduced to 160 pixels on the longer side.
box → split at the median of the widest channel color = average of the box's pixels share = pixels in the box / all pixels
Worked example
The demo image is made of five flat bands: 30%, 25%, 20%, 15% and 10% of the area.
A palette of 5 colors returns exactly these five colors and shares; a photograph has countless colors, so the result is averaged “representatives”.
An estimate: another algorithm gives another palette, and a color on a screen depends on the monitor.
Check a PDF