# Image Palette Extractor (k-means, median cut) > Pull a 2–32 color palette from a photo with k-means in OKLab, median cut or a histogram. Upload a PNG, JPEG, WebP or GIF image and get its main colors with the share of the image each one covers, plus how well the palette represents the image. Download the palette as HEX, GIMP GPL, JASC-PAL, JSON, CSS variables or Adobe Swatch Exchange (ASE). Part of usefulweb.app (https://usefulweb.app/). Part of [Lumina](https://lumina.usefulweb.app/) (ownerApp: lumina). Results are deterministic calculations from the inputs and the listed assumptions; the API returns exactly what the web page shows. ## Use it - Human interface: https://luminapaletteextractor.usefulweb.app/ (interactive tool at https://luminapaletteextractor.usefulweb.app/tool) - JSON API: POST https://luminapaletteextractor.usefulweb.app/api/v1/calculate with a JSON object of inputs (schema: https://luminapaletteextractor.usefulweb.app/api/v1/tool) - OpenAPI: https://luminapaletteextractor.usefulweb.app/openapi.json - MCP (Streamable HTTP): https://luminapaletteextractor.usefulweb.app/mcp - tool `lumina_palette_extractor` ## Inputs - image (file, required): Image (PNG, JPEG, WebP or GIF; up to 25 MB) - method (select): Method - count (integer): Number of colors - name (text): Palette name ## Method - The image is decoded to 8-bit sRGB and scaled so its longer side is at most 512 pixels; pixels with alpha below 128 are ignored. Up to 65,536 pixels are sampled on a fixed stride. - Median cut (Heckbert 1982) splits the colour box with the largest count-weighted error at the weighted median of its widest channel, then refines with four k-means passes in RGB — the same function Flipline Pixel Studio uses. Histogram groups colours into 32 levels per channel and keeps frequent bins that differ by at least about 42 RGB units — the same function as Lumina Palette Studio. - k-means starts from the median-cut colours and runs Lloyd iterations in OKLab, where distances follow perceived differences, until nothing changes (at most 24 passes). Centres outside sRGB are mapped back with the CSS Color 4 method. - Share = fraction of opaque sampled pixels whose nearest palette color (OKLab) is that color. Mean error = average OKLab distance × 100 from each pixel to its nearest palette color; lower is a better fit. Results are deterministic.