Nodes/ComfyUI_BadgerTools/IdentifyColorToMask-badger
ComfyUI Node

IdentifyColorToMask-badger

Select every pixel of a given color — a chroma-key style mask in one node

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
IdentifyColorToMask-badger
  • image
  • IMAGE
  • MASK
color#ffffff
detection_threshold5

Color is a selector. Give IdentifyColorToMask-badger an image and a target color, and it marks every pixel in the image that matches that color - white for match, black for everything else - and hands the result back both as an IMAGE (for previewing) and a MASK (for wiring into the graph). It's the closest thing ComfyUI has to a one-node chroma key.

The uses are more numerous than they first look. Select the sky by its blue, select a clean background by its white, select that one red object, and then feed the mask into an inpainting sampler to swap or regenerate just those pixels, or into ApplyMaskToImage-badger to cut them out as transparency. The KB's background-removal essay is all about how masks are the currency of "take this thing out of the picture" - this node is the color-based way to mint that mask, no segmentation model required. It pairs naturally with GetColorFromBorder-badger in the same pack: read the border's color, then mask exactly that color.

How it works

The node walks every pixel, compares its RGB against your target, and if the Euclidean color distance is within detection_threshold, paints it white. The two things that matter:

  • color (STRING, default #ffffff) - the target color as hex.
  • detection_threshold (INT, default 5) - how tolerant the match is. This is the whole tuning surface. A solid flat color matches at 5; shadows, gradients, and JPEG compression need 30–60. There's no magic number - raise it until the region you want is fully white and the regions you don't are still black.

Inputs and outputs

  • image - the IMAGE.
  • color - target color, #RRGGBB format.
  • detection_threshold - match tolerance, 1 to 4096 in the schema (realistically you live between 5 and 80).

Two outputs, same content, two formats:

  • An IMAGE - the white-on-black mask as a picture, so you can actually see what got selected before you trust it.
  • A MASK - the same thing as a mask tensor, ready for samplers, compositors, or the pack's mask nodes.

The dual output is the design pattern worth copying: preview first, then commit.

Installing it

In ComfyUI_BadgerTools: ComfyUI Manager → search "BadgerTools" → install, or

cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools

Restart after install. No model files - this is pure pixel math, no neural network involved. (Heavy requirements still install and import at startup, the pack's usual tax.)

Gotchas

  • Threshold is a distance, not a percentage. The code computes straight Euclidean RGB distance, so "5" is tight - tighter than most people guess. If your selection comes out patchy, the fix is almost always a bigger threshold, not a different color.
  • Anti-aliased edges betray you. Smooth edges are blends between your color and the background; they'll fall outside a tight threshold and leave a ragged halo. Feather the mask or accept a slightly wider selection.
  • It matches everywhere, not just at borders. That's the difference from IdentifyBorderColorToMask-badger, which only takes the edge-connected region. Same color in the middle of your subject? This node selects it too. Pick the right sibling for the job.

No community threads exist for this node - it's a personal-pack utility with a two-line README. But color-based masking is one of those "it's just a few pixels of logic" jobs that turns out to be genuinely useful the moment you need to pull one thing out of an image without reaching for a segmentation model.

Categorybadger

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
colorSTRING#ffffff
detection_thresholdINT51–4096

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK