Nodes/ComfyUI-Color-Palette/🎨 Image Color Palette Analyzer
ComfyUI Node

🎨 Image Color Palette Analyzer

Pull a real color palette out of any image, percentages included

By leozongmac·Created 5 months ago·Updated 5 months ago· 1
🎨 Image Color Palette Analyzer
  • image
  • palette_image
  • color_info
num_colors5
image_width512

Ever stared at a reference image and wanted to know what's actually in it - not the one color you're squinting at, but the whole distribution? That's exactly what the 🎨 Image Color Palette Analyzer does: give it an image and it hands back the dominant colors as hex codes with their exact percentages, plus a rendered swatch strip you can look at or wire into the rest of your graph.

It's a small, single-purpose node from the ComfyUI-Color-Palette pack by LEOZONG (千澄君), a straightforward utility rather than a heavyweight tool - the kind you drop in for a color-matching job and forget about. No models to download, no API, no GPU needed. It does one thing on your CPU and does it fine.

How it works

The mechanism is K-Means clustering, which is the standard trick for this exact job. The node takes your image tensor, flattens every pixel into a list of RGB triples, then runs scikit-learn's KMeans to group them into num_colors clusters. Each cluster center becomes one palette entry, and the share of pixels in that cluster becomes its percentage. Since the code fixes random_state=42, the same image gives you the same palette every run - good, because the last thing you want from an analysis node is it picking different "dominant" colors each time you press Run.

One honest caveat: it clusters in plain RGB space, not a perceptually uniform space like LAB. That means two very similar-looking shades can end up split into separate clusters, or a muddy midtone can swallow colors your eye clearly separates. It's rarely a dealbreaker for palette extraction, but don't expect Adobe-swatch precision. It's a "good enough" tool, and it knows it.

The inputs and outputs that matter

There are only three inputs, and two of them you'll probably leave alone:

  • image - the IMAGE tensor you want analyzed. Note it only processes the first image in the batch, so feed it a single frame.
  • num_colors - how many colors to extract. Default 5, clamped between 2 and 10. This is the one you'll actually touch.
  • image_width - this one's a trap if you don't read the docs: it's not a resize of your input. It's the width of the output palette image (512 default, 256–1024). The palette strip is always 150px tall; the color blocks scale in width to match each color's percentage.

Two outputs:

  • palette_image - the rendered swatch strip. Pipe it into a PreviewImage to eyeball it, or feed it into anything else that wants an IMAGE.
  • color_info - a STRING with one #hex: pct% line per color, sorted by share. This is the gold; it's made for a Show Text node or any downstream step that wants the palette as data.

The author's own example workflow does exactly that: analyzer → PreviewImage for the strip and Show Text for the breakdown.

Installing it

The pack is a single-file affair. In a terminal:

cd ComfyUI/custom_nodes/
git clone https://github.com/leozongmac/ComfyUI-Color-Palette
cd ComfyUI-Color-Palette
pip install -r requirements.txt

Then restart ComfyUI. The dependency list is blessedly short - just scikit-learn - which is good news, because it also means the one real install gotcha is that scikit-learn drags in numpy/scipy, and every custom node in ComfyUI shares one Python environment. If you already have a node that pins an older numpy, this install can rattle that cage. That's the standard custom-node tax, not this pack being special. ComfyUI Manager may list it as "ComfyUI-Color-Palette" too, though this is obscure enough that the manual clone above is the reliable path.

Common issues

Since it's CPU-only sklearn, the main failure you'll hit is the classic one: load a community workflow, get told this node is missing, and have to install a pack you've never heard of - that's this pack, since it's not a household name. The fix is the three commands above.

Beyond that, the only behavior to watch is the palette image's text labels: the code only draws the hex/percentage text inside a block if it's wider than 50px. With num_colors set high and a narrow image_width, some blocks drop their labels - bump image_width to 1024 and you're fine. And since it clusters in RGB directly, near-black or near-white gradients tend to collapse into one flat "dark" or "white" entry. That's the clustering, not a bug, and if you're pulling a palette to match a LoRA's color mood or steer a color-constrained model, it's usually exactly what you wanted.

Categoryimage/analysis

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
num_colorsINT52–10
image_widthINT512256–1024

Outputs (2)

NameTypeDescription
palette_imageIMAGE
color_infoSTRING