Smart Image Palette Extract
Every unique color in your image, as a strip
- image
- palette
- num_colors
There's a meaningful difference between "extract the dominant colors" and "extract the unique colors." The first gives you a tidy 5-swatch summary. The second gives you every single distinct color that appears - potentially hundreds of them - which is what you want when you're cataloging an image's true color content, building a swatch library, or checking exactly how many colors a piece of art actually uses. Smart Image Palette Extract is firmly in the second camp, and it's honest about it.
How it works
It flattens the image to its unique pixel colors (using numpy's unique), sorts them into a sensible order (hue, then luminance, then saturation - the same sort the pack's convert node uses), and renders them as a 1-pixel-high palette strip. It also outputs num_colors, the actual count, as an integer you can wire into a text display or use as a condition elsewhere.
Two behaviors to know about before you wire it up:
max_colorscaps it, hard. Default 255. If the image has more unique colors than the cap, the node raises an error rather than truncating - that's a deliberate fail-fast, and it means feeding it a noisy photo at the default 255 will throw. Raise the cap (max 255) or feed it cleaner input.- It only looks at the first frame of a batch. If you hand it a video batch or a multi-frame input, you get the palette of frame 0. Fine for stills, surprising for batches.
Inputs and outputs
image- the image to analyze (first frame only).max_colors(optional) - maximum unique colors allowed, default 255.
Outputs: palette (the color strip as an IMAGE) and num_colors (an INT).
Installing it
From the ComfyUI-SmartImageTools pack:
cd ComfyUI/custom_nodes
git clone https://github.com/slvslvslv/ComfyUI-SmartImageTools
pip install -r ComfyUI-SmartImageTools/requirements.txt
Restart ComfyUI, or use ComfyUI Manager ("SmartImageTools"). Just numpy - no heavy lifting.
Where it fits
It pairs naturally with the pack's palette workflow: extract a real palette from a reference, hand it to SmartImagePaletteConvert as reference_image, and your generated image inherits that exact color set. The fail-fast error is actually the feature to respect - if you're working from a photographic source, either bring the image down to a clean, limited-color version first or accept that "unique colors" on a JPEG is going to be a big number. For genuinely posterized or flat-color art, though, this is the exact tool you want.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| max_colorsopt | INT | 2551–255 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| palette | IMAGE | — |
| num_colors | INT | — |