Dominant Colors
The K-means palette extractor for when you need the actual palette
- image
- dominant_colors
- color_percentages
Dominant Colors is the node for when you look at an image and want to know - programmatically, not by squinting - what its actual palette is. Feed it an image, tell it how many colors you want, and it returns the dominant colors plus the percentage of pixels each one occupies. If you've ever wanted to match a generated image's palette to a reference, or check "did this img2img pass drift the colors?" this is the cheap way to get the answer as data.
How it works
It's K-means clustering under the hood, straight out of scikit-learn: the image is reshaped into a pile of pixels and clustered into num_colors groups; the cluster centers are your dominant colors, and the share of pixels in each cluster is your percentage. The implementation pins random_state=42 and runs 10 initializations, so results are reproducible - same image in, same palette out, every time. That's a small thing you'll appreciate when you're diffing outputs across runs.
The inputs that matter
- num_colors - 1 to 20, default 5. For a "what's this image about" read, 5 is right. For palette matching or web design, 8–12 gives a better spread; 20 starts to disintegrate into noise. Note K-means can occasionally return fewer distinct colors than requested when the image is nearly monochrome - that's the algorithm, not a bug.
- color_format - RGB, HSV, or HEX. HEX is the one you'll actually use: it spits out
#rrggbbstrings ready for a style guide or a design tool. HSV is useful if you care about hue relationships rather than exact values. - input_mode -
tensor(default, from the graph) orfile(viaimage_path).
Outputs are dominant_colors and color_percentages, both JSON strings. The percentages sum to ~1 and tell you how dominant the palette actually is - a landscape photo might give you 40% sky, 25% grass; a busy scene spreads thin across many colors.
Install
Part of the pack, installed like everything else here:
cd ComfyUI/custom_nodes
git clone https://github.com/APZmedia/ComfyUI-color-tools
or via ComfyUI Manager, searching "ComfyUI Color Profile Reader," then restart. The README's manual clone command contains a placeholder URL - the real one is APZmedia/ComfyUI-color-tools. The dependency story matters more here than for the reader nodes: K-means needs scikit-learn and the HSV/HEX formatting path uses OpenCV (via cv2.cvtColor). Both are in the pack's optional-deps list, and install.py will try to add them on startup - but if you installed the pack long ago, or pip installs failed, this node won't be in your node list while the reader nodes are. Check the startup log for the color-analysis warning line before assuming something else broke.
The workflow
Wire dominant_colors into a Show Text node and you have your palette as copy-pasteable data. Pair it with ColorSimilarity (to find where in the image a palette color actually lives) and you've got a small color-analysis toolkit that outputs structured JSON rather than vibes.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_mode | COMBO | tensor | 2 options: file, tensor |
| num_colors | INT | 51–20 | — |
| color_format | COMBO | RGB | 3 options: RGB, HSV, HEX |
| imageopt | IMAGE | — | |
| image_pathopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| dominant_colors | STRING | — |
| color_percentages | STRING | — |