π¨ Color Palette Extractor
Get the five colors that actually make up an image, as an image you can use
- image
- palette_image
You've got an image whose color palette you love and you want to turn it into something you can act on - a swatch sheet for a design client, a reference for color grading, or a prompt input for the next generation. Eyeballing hex codes out of an image is misery. π¨ Color Palette Extractor just hands you the dominant colors as a clean vertical-bars swatch image, sized however you like.
It's the kind of node that sounds trivial and turns out to be quietly useful, because the output isn't a list of numbers you have to copy - it's an actual palette_image you can preview, save, or feed into a color-matching stage downstream. Pair it with this pack's Color Match and you've got a two-node "steal this mood" pipeline: extract the palette, then match a new render to it.
How it works
The mechanism is a straight k-means clustering on the image's pixels. The node resizes the image down (the same _kmeans_hex helper does Lanczos downscale to a 120Γ120 working blob before clustering, so it stays fast on 4K inputs), runs k-means to find the num_colors dominant clusters, and orders them by how much of the image each one covers. Then it draws the proportional vertical bars and pads out the result to your requested dimensions.
The inputs you actually touch:
num_colors(2β20, default 6) - how many swatches you want. Six is the sweet spot for a "mood" palette; push to 12+ and you start getting shades of the same hue.output_width/output_height- the size of the swatch image. Default 1000Γ400 is a sensible presentation bar; the 8px step hints these get reused as a visual reference, not pixels to render from.min_ratio(0β0.5, default 0.01) - the minimum proportion of the image a color must cover to be kept. If you're seeing noisy one-pixel "colors" at the end of the palette, nudge this up to drop the trivia.
Output is a single palette_image of type IMAGE. That's it.
Where it earns its place
The genuinely useful workflows: extract a palette from a real photo and use it as the ref_image/color guidance for a generation; pull palettes across a folder of reference images with Folder Image Loader to see at a glance whether your dataset's colors are consistent; or export swatch sheets for branding. For the last one, note the swatch is proportional (each bar's width reflects coverage), which is more useful than an even split if you care which color dominates.
Installing it
Part of the Louis Use pack:
cd ComfyUI/custom_nodes
git clone https://github.com/LouisLU1997/ComfyUI-louis-use Louis_use
Or "Louis Use" in ComfyUI Manager, then restart. Pure numpy/Pillow, no model downloads, nothing heavy.
What it won't tell you
k-means gives you the dominant colors, not the distinctive ones. A mostly-gray image with one red accent will hand you five grays and one red - the red still shows up, but ranked by coverage it's last. That's inherent to the approach, not a bug. If you want a "signature" palette that ignores the boring background, crop the interesting region first and run the extractor on that. Otherwise, for a free tool this thing is a surprising amount of work for zero setup.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| num_colors | INT | 62β20 | β |
| output_width | INT | 100064β4096 | β |
| output_height | INT | 40064β4096 | β |
| min_ratio | FLOAT | 0.0100β0.5 | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| palette_image | IMAGE | β |