LayerUtility: Get Main Colors V2
Get Main Colors V2 — pull the five dominant colors out of any image
- image
- preview_image
- color_1
- color_2
- color_3
- color_4
- color_5
Point this at an image and it hands you back its five dominant colors as hex strings, plus a little swatch strip so you can see them. It's a palette extractor. Simple idea, genuinely useful in a workflow because those hex values are strings you can wire straight into other nodes - a stroke color, a solid-color background, a text overlay tint - so the palette of one image can drive the styling of another.
Where it earns its place: matching a generated element to a brand palette, pulling the mood colors out of a reference to reuse elsewhere, or just inspecting what an image is actually made of before you grade it. It turns "this image's colors" into data you can act on.
How it works
It runs k-means clustering on the image's pixels, grouping them into five color clusters and returning each cluster's representative color. K-means is the standard "find the N dominant colors" algorithm - it partitions all the pixels into groups by similarity and gives you the center of each group. The k_means_algorithm choice picks which implementation does the clustering; the result is the same five-color idea either way.
The inputs and outputs that matter
image- the source to analyze.k_means_algorithm-lloydorelkan. Both are k-means;elkancan be faster on some data,lloydis the classic. Don't overthink this - it changes speed, not the concept.
Outputs are a preview_image (the swatch strip, so you can eyeball the palette) plus five separate hex strings, color_1 through color_5, ordered by dominance. Wire any of those hex outputs into a node that takes a color string.
How to install it
Ships with the LayerStyle pack. ComfyUI Manager → search LayerStyle → install → restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
pip install -r ComfyUI_LayerStyle/requirements.txt
then restart. Under 😺dzNodes → LayerUtility. No model download - it's clustering, not a neural net.
Common issues & troubleshooting
The five colors are muddy or too similar. If the image is dominated by one hue or lots of near-blacks, k-means spends its clusters there and the palette looks flat. That's the image, not a bug - crop to the region you actually care about before analyzing.
A color output won't connect to the node I want. These are hex strings. They plug into inputs that expect a color string (like a stroke or fill color field). If a node wants an actual COLOR type or RGB tuple, you may need a small conversion node in between.
Order isn't what I expected. The colors come out ranked by how much of the image they cover, not by brightness or position. The most-present color is color_1.
Node missing from the menu. The LayerStyle pack didn't import - commonly a broken transformers dependency (a stray TensorFlow) crashing the whole pack on load. Read the traceback, use Manager's "Try Fix," or repair the offending library.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| k_means_algorithm | COMBO | 2 options: lloyd, elkan |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| preview_image | IMAGE | — |
| color_1 | STRING | — |
| color_2 | STRING | — |
| color_3 | STRING | — |
| color_4 | STRING | — |
| color_5 | STRING | — |