ComfyUI Node Runs on cloud

Color Clip

Chromakey for flat-color images

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
Color Clip
  • image
  • color
  • IMAGE
targetTO_BLACK
complementTO_WHITE

Imagine a green screen, except the "green" can be any color and the screen is a flat-color image you already have. That's Color Clip: it takes an image, a target color, and repaints every pixel of that exact color to black or white - while doing whatever you choose with every other pixel. It's a masking/compositing helper, part of the comfyui_bmad_nodes pack, and it's the node you reach for when you need to carve one color out of a synthetic image.

It shines on images with flat, deliberate color regions: semantic segmentation maps, color-coded label images, UI renders, QR codes, or a solid-color object shot against a different solid background. One pass and your target color becomes a clean monochrome silhouette you can feed into a collage or chain onward.

How it works

The mechanism is dead simple - per pixel, it checks whether the pixel equals your color exactly, then applies one of three operations to that pixel and another to everything else:

  • TO_BLACK - repaint to rgb(0,0,0)
  • TO_WHITE - repaint to rgb(255,255,255)
  • NOTHING - leave the pixels as they are

You get two independent selectors: target (what happens to the matching color) and complement (what happens to everything else). The classic mask recipe is target TO_BLACK, complement TO_WHITE: the color you picked goes black, the rest goes white, and you have a binary matte.

The inputs that matter:

  • image - any IMAGE tensor.
  • color - the color to clip out. Wire this from the pack's Color (RGB) node, or from any node that outputs a COLOR.
  • target and complement - the two enums above.

The one output is an IMAGE, not a MASK. If the next node wants a mask, convert with ConvertImg (GRAY) or feed the image into a mask-aware node that accepts it.

The exact-match trap

Because the comparison is pixel-equal, this is for flat colors, not photographs. A "red car" has a thousand shades of red in the pixels; Color Clip will only grab the exact (255,0,0). If your source image is a JPG, compression noise alone can kill the match. Feed it PNG renders or segmentation output, and you'll be fine. If you need fuzzy color distance, that's what the ADE20k variant's tolerance is for - Color Clip ADE20k is the sibling that handles class colors from semantic maps.

Install

It ships with the pack, so:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt

or install "comfyui_bmad_nodes" via ComfyUI Manager and restart. The pack's requirements (opencv-python, scikit-image, gray2color, simpleeval) auto-install - this particular node only really needs OpenCV, but you get them all anyway.

One tip: because there's no tolerance setting here, if your "flat" color is slightly off, nudge it - or just re-render the source with the exact color you're clipping.

CategoryBmad/image

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
targetCOMBOTO_BLACK3 options: TO_BLACK, TO_WHITE, NOTHING
complementCOMBOTO_WHITE3 options: TO_BLACK, TO_WHITE, NOTHING
colorCOLOR

Outputs (1)

NameTypeDescription
IMAGEIMAGE