📊 PIP 高级颜色分析
Find out what colors are actually in your image
- image
- 主导色
- 辅助色
- 平均亮度
- 平均饱和度
- 分析图
You've got a render and you want text (or a LoRA, or a background) that matches its palette. Eyeballing hex values from a preview never goes well. PIPAdvancedColorAnalyzer, from the PIP_ArtisticWords pack, does the boring sampling work for you: it pulls the dominant colors out of any image, reports average brightness and saturation, and draws you a little analysis chart you can actually look at.
What it does
Feed it any IMAGE, and it returns the dominant color and a secondary color as hex strings (#rrggbb), the image's average brightness and saturation as floats (0–1-ish), and a generated IMAGE - an analysis panel showing swatches with their percentages. It's a read-only utility; nothing gets written to disk.
How it works
The interesting part is the sampling strategy. Instead of scanning every pixel (slow on 4K images), it auto-computes a sample count from the image dimensions - roughly sqrt(total_pixels) * 1.5, clamped between 2000 and 50000 - then samples on a uniform grid. Colors get bucketed with a Counter, the top bucket is the 主导色, and a secondary color is picked that's sufficiently distinct from it, so you don't get "dark gray" as the "different" second color. There are two hidden inputs in the code (auto_sample and sample_points) but they're not exposed in the node UI - the defaults are sensible, and you can't really break them.
The inputs and outputs that matter
Inputs are minimal, and that's a feature:
- image - the
IMAGEto analyze (required). - num_dominant_colors - how many dominant colors to consider (2–20, default 8). It mainly affects how good a distinct secondary color the node can find, so leave it near the default unless you're chasing a very specific swatch.
Outputs (Chinese labels, as this pack likes):
- 主导色 (
STRING) - the main color as a hex string. - 辅助色 (
STRING) - a distinct secondary color. - 平均亮度 (
FLOAT) - average brightness. - 平均饱和度 (
FLOAT) - average saturation. - 分析图 (
IMAGE) - a rendered analysis panel with color swatches and percentages. Preview it or save it; it's the only visual output.
Why you'd wire it in
The honest use is pairing it with the pack's own color pipeline. Feed the 主导色 hex into PIPColorWheel to build a scheme, or match against the color_match logic of the PIP Artistic Text Generator. Beyond that it's a general palette-extraction tool - the analysis image alone is handy documentation of what a frame is actually made of.
Installing it
Part of the same pack, installed once:
cd ComfyUI/custom_nodes
git clone https://github.com/chenpipi0807/PIP_ArtisticWords.git
cd PIP_ArtisticWords
pip install -r requirements.txt
Or search "PIP Artistic Words" in ComfyUI Manager. Restart afterwards. Deps are just Pillow, numpy, opencv-python and webcolors - no models, no GPU.
Gotchas
- It prints a lot. On every run it logs the computed sample count, grid size, and strategy to the console. Fine for development, mildly annoying when it's just sitting in a workflow.
- "Dominant" means most pixels, not most important. A big flat sky will dominate over a small vivid subject. That's an inherent limit of bucket-counting, not a bug.
- Hex strings are lowercase.
#4096ff, not#4096FF. Most color inputs (including the pack's own) accept both, but if you're string-comparing outputs somewhere, normalize case first. - The analysis image is generated by Pillow and uses the pack's bundled 方正风雅宋 font for labels - if that font file ever gets deleted, it silently falls back to a default bitmap font.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| num_dominant_colors | INT | 82–20 | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| 主导色 | STRING | — |
| 辅助色 | STRING | — |
| 平均亮度 | FLOAT | — |
| 平均饱和度 | FLOAT | — |
| 分析图 | IMAGE | — |