Nodes/ComfyUI-SBTools/Alpha to Chroma Key (SBTools)
ComfyUI Node

Alpha to Chroma Key (SBTools)

Stop hand-picking green screen colors — this node finds one your subject never uses

By Amatsukast·Created 5 months ago·Updated 21 days ago· 2
Alpha to Chroma Key (SBTools)
  • image
  • HEX_COLOR
  • FILLED_IMAGE
min_distance30
sample_size5000

You cut a subject out of a photo with SBTools_BiRefNet, you've got a lovely transparent PNG, and now your video editor is looking at you funny. After Effects, Premiere and DaVinci Resolve all want to key a solid color out of footage - they don't care about your alpha channel. So what color do you fill the transparency with? This node answers that for you: it scans your image, finds the color that's most different from everything the subject actually contains, and fills the empty pixels with it.

It's a small, focused idea, and it's the most original node in the pack. The author's framing is "find unused color, fill background," and it's genuinely the missing step between "cutout done" and "ready to hand to a video pipeline."

How it works

The algorithm is straightforward and honestly pretty elegant. It randomly samples sample_size pixels from your image (default 5000), then measures the Euclidean RGB distance from each of six classic keying candidates - pure green, magenta, blue, cyan, yellow, and red. It keeps whichever candidate has the largest minimum distance from your sampled pixels, as long as that minimum clears your min_distance threshold. That's the whole trick: it's not picking "a nice green," it's picking the candidate that has the most clearance from every color your subject uses. If no pure color qualifies, it falls back to a coarse grid search across RGB space so it still returns something useful.

Once it has a color, it composites your RGBA image over it using the alpha channel, so transparent areas become the key color and the subject stays intact. You get both the HEX_COLOR (so you can set your keyer's eyedropper to match) and the FILLED_IMAGE ready to drop into a video node or save out.

The inputs that actually matter

  • image - your transparent-background image. This is the one you'll feed from a background-removal node.
  • min_distance (default 30, range 0–255) - the minimum color distance required from existing colors. Higher is safer but harder to satisfy; the tooltip suggests 30–60 for keying. If your green screen ends up bleeding into the subject, raise it.
  • sample_size (default 5000, range 1000–50000) - how many pixels it samples. Complex palettes want more; you'll rarely need to touch it.

Outputs are HEX_COLOR (STRING) and FILLED_IMAGE (IMAGE).

One gotcha worth knowing: if the input has no alpha channel at all, the node just prints the safe color and returns the image unchanged - no fill. So don't feed it a flat RGB image and wonder where your background went.

Installing it

It ships in the ComfyUI-SBTools pack, so this is the same install as every node in it. Easiest is ComfyUI Manager → Custom Nodes Manager → search "ComfyUI-SBTools" → Install, then restart. Or do it by hand:

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

Dependencies are light - just huggingface_hub and kornia - and restart ComfyUI after.

Troubleshooting

  • Filled color too close to the subject - your min_distance is too low. Bump it to 40–60 and re-run.
  • It picks magenta/blue instead of green - that's not a bug. The subject might genuinely contain more green than anything else; the node optimizes for clearance, not for looking like a proper green screen. Green is the common result, but any of the six candidates can win.
  • Slow on big images - lower sample_size. The default is a good balance, but 50k samples on a 4K frame adds up.

Pair it with BiRefNet for the full remove-and-key pipeline, and you've got a compositing setup that doesn't require you to guess a single hex value.

CategorySBTools/Image

Inputs (3)

NameTypeDefaultDescription
imageIMAGEInput image to analyze for finding a safe chroma key color.
min_distanceINT300–255Minimum color distance required from existing colors (higher = more different, recommended: 30-60 for chroma keying).
sample_sizeINT50001000–50000Number of pixels to sample for analysis (higher = more accurate but slower).

Outputs (2)

NameTypeDescription
HEX_COLORSTRING
FILLED_IMAGEIMAGE