Nodes/Img2color - Extract Colors from Image/Img2Color - Color Palette Extractor
ComfyUI Node

Img2Color - Color Palette Extractor

Turn any image into a named color palette you can wire into your prompt

By christian-byrne·Created 2 years ago·Updated 2 years ago· 16
Img2Color - Color Palette Extractor
  • input_image
  • plain_english_colors
  • rgb_colors
  • hex_colors
  • xkcd_colors
  • design_colors
  • common_colors
  • color_types
  • color_families
num_colors5
get_complementaryfalse
k_means_algorithmlloyd
accuracy60
exclude_colors

You've got a reference image with a color story you want to reuse - a sunset photo, a product shot, a piece of art - and you want the next image you generate to live in that same palette. That's exactly the gap bmy_Img2ColorNode (shown as "Img2Color - Color Palette Extractor") fills. Drop an image in, and it hands you the dominant colors as hex codes, RGB values, and plain-English names like "saddle brown" or "medium violet red," ready to paste into a prompt or feed into another node. It doesn't call any API, needs no key, and runs entirely on your machine. It's a small utility, and it's very good at the one thing it does.

The pack ships a single node, and it's an output node: the results render straight into a floating text window, no extra viewer needed. If your goal is palette-aware prompting, this is the one I'd reach for before the fancier image-analysis suites - it does the one job cleanly and names the colors in a way humans and prompts actually understand.

How it works

Under the hood it's KMeans clustering via scikit-learn. The image's pixels are flattened into a big list of RGB triplets, and KMeans is asked to find num_colors clusters. The cluster centers are your palette. Straightforward, no neural net involved, no model download - the "AI" here is just a classic clustering algorithm doing classic work.

A couple of quirks worth knowing. The accuracy slider (default 60, out of 100) doesn't measure quality - it scales how many KMeans iterations run (roughly 512 × accuracy/100). Crank it up for more refinement on noisy images; leave it alone for most cases. Second, the node tries to borrow a seed from the first KSampler it finds in your workflow, so results are reproducible when a sampler is present. If your workflow has no KSampler, the palette can drift a bit between runs - KMeans starts from a random position. If that bothers you, don't fight it; just note the palette you liked and pin it yourself.

The inputs and outputs that matter

You'll touch maybe three settings. input_image is required, obviously. num_colors (default 5, up to 128) is how many colors to extract - keep it small for clean palettes, raise it for a detailed breakdown. get_complementary swaps the detected palette for its complementary colors (literally 255 − channel per color), handy when you want a palette that opposes the source instead of matching it. There's also exclude_colors, a comma-separated list of names (like black, white) to filter out of the results, and k_means_algorithm, which you can safely leave on lloyd.

The outputs are eight strings, each a comma-joined list in a different naming system. The ones you'll actually use: hex_colors (the #RRGGBB values - best for wiring into other nodes or a palette preview), common_colors (about 120 everyday names; the author's own tooltip calls this the most useful level), and plain_english_colors (the closest CSS3/CSS2/CSS2.1/HTML4 web color name). The rest - xkcd_colors (~950 names, finest granularity), design_colors, color_types (light/dark/saturated), color_families, and rgb_colors - are there if you need a different vocabulary. Feed a string output into a prompt-builder node for palette-aware txt2img, or use it alongside img2img for stronger color adherence. The repo's example workflows show exactly those patterns.

Installing it

The pack is on the Comfy Registry, so the easy path is ComfyUI Manager: search for "Img2color - Extract Colors from Image" and hit install, then restart. Manual install is the usual dance:

cd ComfyUI/custom_nodes
git clone https://github.com/christian-byrne/img2colors-comfyui-node
cd img2colors-comfyui-node
pip install -r requirements.txt

Then restart ComfyUI. On the Windows portable build, install into the embedded Python (...\python_embeded\python.exe -m pip install -r requirements.txt) rather than your system Python.

Gotchas

The one real install gotcha is scikit-learn, the heavyweight of the three requirements (scikit_learn>=1.4.0, plus pinned colornamer==0.2.3 and webcolors==1.13). ComfyUI doesn't ship it, and because custom nodes all install into the same Python environment with no isolation, it can occasionally collide with another pack's pins. If the node throws a ModuleNotFoundError for sklearn or colornamer, that's the cause - re-run the pip install into the environment ComfyUI actually uses.

One more: newer scikit-learn (1.5+) removed the old KMeans algorithm values, so if you flip k_means_algorithm off the default lloyd to full or auto and get an error, that's why. It's the one setting that can bite; the default is fine.

Categoryimg2txt

Inputs (6)

NameTypeDefaultDescription
input_imageIMAGE
num_colorsoptINT51–128Number of colors to detect
get_complementaryoptBOOLEANfalseGet the complementary colors of the detected palette
k_means_algorithmoptCOMBOlloyd4 options: lloyd, elkan, auto, full
accuracyoptINT601–100Adjusts accuracy by changing number of iterations of the K-means algorithm
exclude_colorsoptSTRINGComma-separated list of colors to exclude from the output

Outputs (8)

NameTypeDescription
plain_english_colorsSTRINGPlain English Colors correspond to the closest named color in the CSS3, CSS2, CSS21, and HTML4 color dictionaries.
rgb_colorsSTRINGRGB Colors are in the format "rgb(255, 0, 255)"
hex_colorsSTRINGHex Colors are in the format #RRGGBB
xkcd_colorsSTRINGXKCD Color is the finest level of granularity, and corresponds to the colors in the XKCD color survey. There are about 950 colors in this space.
design_colorsSTRINGDesign Color is the next coarsest level. There are about 250 Design Colors
common_colorsSTRINGCommon Color is the next coarsest level. There are about 120 Common Colors. This is probably the most useful level for most purposes.
color_typesSTRINGColor Type is another dimension that tells, roughly, how light, dark or saturated a color is. There are 11 color types.
color_familiesSTRINGColor Family is even coarser, and has 26 families. These are all primary, secondary, or tertiary colors, or corresponding values for neutrals.