ComfyUI Node

BackgroundColor

The most boring node in the pack — and the one that makes background swapping work

By yondonfu·Created 2 years ago·Updated 2 years ago· 22
BackgroundColor
  • images
  • IMAGE
colorblack

BackgroundColor does exactly one thing: it takes any image (or batch of images) and spits out a solid black, red, blue, or green version of it, same size, same batch. That's it. No sliders, no hex picker, no gradient. It looks like filler, but it's the "swap" half of the pack's background swapping - the node that hands your Composite something to put behind the subject.

The pack is yondonfu's ComfyUI-Background-Edit, a set of nodes for blurring, removing, or swapping image/video backgrounds with CUDA acceleration, built with real-time workflows in mind (the same author makes comfystream). The README's swapping demo is literally a blue version of your input image composited under a cutout subject. That blue image came from this node.

How it works

The implementation is almost insultingly direct: it allocates a zero tensor shaped like your input (torch.zeros_like(images)), then for red, green, or blue it sets exactly one color channel to 1.0. Black is just the zeros. Total cost is one memory allocation - you cannot make this node slow.

The part that actually matters is what it preserves. Because the output is built from zeros_like(input), it keeps the input's exact height, width, and batch count. Feed it a 30-frame video batch and you get 30 solid-color frames out. That's not an accident - it's what lets the output line up with the foreground frames in Composite, which hard-errors if the batch counts of its three inputs disagree.

The inputs and output

Only two inputs, from the node schema:

  • images (IMAGE) - anything, but wire it from the same image feeding your foreground and mask so the dimensions stay consistent.
  • color - a dropdown with exactly four choices: black, red, blue, green. Default is black.

Output is a single IMAGE of the same shape, ready to plug into Composite's backgrounds input.

One thing to get straight: this is not a chroma-key or an alpha channel. It's a flat RGB fill. Blue here means "a solid blue picture", not "a green screen we'll key out later." If you want an arbitrary color, other packs' solid-color nodes will give you a hex picker; this one is deliberately fixed at four colors because it exists for the depth-based swap workflow, not for art direction.

Install

It's a tiny pack - no bundled model files, and its only Python dependencies are torch and torchvision, which you already have if ComfyUI runs at all. Easiest path is ComfyUI Manager (search "ComfyUI-Background-Edit"), or from the CLI:

cd ComfyUI/custom_nodes
git clone https://github.com/yondonfu/ComfyUI-Background-Edit
cd ComfyUI-Background-Edit
pip install -r requirements.txt

Restart ComfyUI after. The torchvision line is a slightly unnecessary pin, but it's harmless - everything it needs is already installed.

Where people get burned

The realistic failure is expecting more than four colors, and the workaround is simply to use a different node when you need that. The subtler trap: the color applies to the whole batch. If you're compositing per-frame video you can't give frame one a red background and frame two blue in a single call - you'd split the batch. For the README's actual use case (one solid background under one foreground), none of that matters. Boring node, boring job, and it does it without ever being the reason a workflow fails.

Categorybackground-edit

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
colorCOMBOblack4 options: black, red, blue, green

Outputs (1)

NameTypeDescription
IMAGEIMAGE