Nodes/ComfyUI S4Tool Image/💀Image Primary Color
ComfyUI Node

💀Image Primary Color

What's the dominant color, and here's the hex for it

By S4MUEL-404·Created about a year ago·Updated 10 months ago· 4
💀Image Primary Color
  • image
  • preview_image
  • color
algorithmK-Means Clustering

"Pick the main color of this image" sounds trivial until you actually try to define main. Is it the most common color, the most saturated one, or the color at the center of the image? They're different answers. 💀Image Primary Color from the S4Tool-Image pack lets you choose your definition, and hands back both a visual preview and a hex string you can feed straight into other nodes.

Under the hood it shares a color-extraction engine with the pack's other palette nodes. The engine downsamples the image, then runs one of five algorithms and returns the single dominant color as an RGB value. Since the output includes a usable hex string, the obvious real-world use is automation: pull the dominant color of a reference image, feed that hex into a color-conditioning workflow, or use it to build a matching background.

The inputs that matter

  • image - the IMAGE to analyze.
  • algorithm - this is where the choice lives, and it's worth knowing what you're picking between:
    • K-Means Clustering (default) - clusters pixels in color space and returns the biggest cluster's center. Good all-rounder for a typical photo.
    • Median Cut - splits the color space by histogram median recursively. Fast, usually close to K-Means, a little more sensitive to noise.
    • Histogram Frequency - literally the most common color. Picks up the wall color in a scene, not the "mood" color.
    • High Saturation - filters to vivid pixels first, then extracts. The one to pick when you want the brand-color take, e.g. for product images.
    • Center Weighted - weights the middle of the frame more. Good for portraits or subjects that sit center-frame.

Outputs: preview_image (a small color-block strip so you can see the result at a glance) and color (STRING, the hex like #A1B2C3). That string is the part you'll route into a text node, a color widget, or anywhere that accepts a hex value.

Install

Standard S4Tool-Image pack install:

cd ComfyUI/custom_nodes/
git clone https://github.com/S4MUEL-404/ComfyUI-S4Tool-Image.git
pip install -r ComfyUI-S4Tool-Image/requirements.txt

Or ComfyUI Manager → search "S4Tool-Image" → Install → restart.

No models - scikit-learn and numpy only, both in the pack requirements.

Gotchas

  • "Wrong" dominant color - almost always an algorithm choice, not a bug. If K-Means returns the beige wall you didn't want, switch to High Saturation or Center Weighted.
  • It's one color, not a mood board - if you want the full story, the pack's 💀Image Palette gives five colors with sorting, and 💀Image Palette 6-3-1 gives three. This node is the minimal version.
  • Hex strings are lowercase sometimes - the output format isn't guaranteed uppercase; don't build anything that case-matches strictly.

It's a tiny node with a narrow job, but "give me the color that defines this image as a string" is genuinely useful glue for automating color-consistent workflows - and this is the one-stop version of it.

Category💀S4Tool

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
algorithmCOMBOK-Means Clustering5 options: K-Means Clustering, Median Cut, Histogram Frequency, High Saturation, Center Weighted

Outputs (2)

NameTypeDescription
preview_imageIMAGE
colorSTRING