ComfyUI Node

RGBColorDetection

The slower sibling that actually catches color tints

By DrMWeigand·Created 2 years ago·Updated 2 years ago· 4
RGBColorDetection
  • image
  • is_color
  • mean_deviation
threshold0.15
det_pixel_percent0.10

Everyone's got that batch of images that's almost all black and white, except some have a subtle sepia or warm cast, and now you're squinting at thumbnails trying to sort them. RGB Color Detection - the second node in DrMWeigand's Color Image Detection pack - is built for exactly that. Its sibling, LAB Color Detection, is faster but misses subtle tints. This one is slower, and it's slower on purpose, because it's looking harder.

How the harder look works

Instead of checking a color-opponent distance, it converts the image to RGB and asks a simpler question per pixel: how far is each pixel from the average of its own three channels? A gray pixel sits close to that line; a colored pixel doesn't. It takes the absolute deviation of every pixel, sorts them, and then - this is the clever part - ignores the bulk of the image and averages only the top det_pixel_percent of the most-deviated pixels. mean_deviation above threshold means is_color = True.

Why bother with the top percentage? Because one saturated red object in an otherwise gray photo would get drowned out by a whole-image average. By looking only at the most colorful pixels, the node catches the tints and the accents that a naive mean would miss - which is precisely where LAB trips up.

The inputs that matter

Three, and two of them are tunable knobs:

  • image (IMAGE) - the picture to classify.
  • threshold (FLOAT, default 0.15) - the deviation cutoff. Higher = harder to call something "color."
  • det_pixel_percent (FLOAT, default 0.1) - what percentage of the most-deviated pixels to actually average.

Here's where people get burned: this value is a percentage, and the code divides it by 100. So the default 0.1 means it averages only the top 0.1% of pixels. If you meant "look at the most colorful 10%," you need to type 10, not 0.1. Cranking it up makes the node more sensitive to small colorful details; dropping it makes it stricter. The default is fine for most images, but knowing the unit is the difference between "why does everything say True" and "oh, that's why."

Both outputs earn their keep:

  • is_color (BOOL) - the verdict.
  • mean_deviation (FLOAT) - the averaged deviation, your threshold-tuning feedback.

The BOOL wires straight into a switch node (core's Switch (Any), or rgthree's Power Switch) so you can route color images down one path and grayscale down another - color-grading pass, an upscaler, a different sampler, whatever you want gated on the answer.

Installing it

Identical to its sibling - one pack, two nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/DrMWeigand/ComfyUI_ColorImageDetection

Then restart. Or use ComfyUI Manager and search "Color Image Detection." Dependencies are just numpy, torch, and opencv-python; if you've installed any OpenCV-based pack you already have them. Nothing heavy, no model downloads.

The gotchas

The README is upfront: this is the reliable-but-slower option. The sort-then-average step costs real time on large batches, so if you're triaging hundreds of frames and they're clean color-or-gray, LAB is the smarter default and this is the fallback for tinted material.

And the same batch quirk its sibling has: feed multiple images at once and only the last frame's result is returned - the loop overwrites both outputs every pass. Feed one image at a time, or expect "last frame wins." Neither node is going to replace a trained classifier, but for "is this thing colored, and should I treat it differently downstream," this is the node that gets the tinted ones right.

CategoryImage Analysis

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
thresholdFLOAT0.15
det_pixel_percentFLOAT0.10

Outputs (2)

NameTypeDescription
is_colorBOOL
mean_deviationFLOAT