Chroma_Key_Alpha
Green-screen keying without a green screen — chroma key by color, not hardware
- imga
- imgb
- IMAGE
Chroma_Key_Alpha is a chroma-keyer, but with a twist that makes it genuinely useful in ComfyUI: it keys against a reference color rather than assuming you shot against a physical green screen. You feed it your image and a sample of the color you want to remove, and it produces a keyed mask. That means you can key out a solid-color backdrop in generated art, or any dominant color in a render, without ever owning a green screen.
The README describes the classic pipeline - convert to HSV, define the green range, feather the mask - but the actual formula takes a simpler, reference-color approach. It's worth reading because it tells you exactly how it behaves:
imgb = imgc + imgb[0, 1, 1, :] # sample the key color
chomachannel = np.sum((imga * imgb), axis=-1)
softmask = chomachannel - np.sum(imga, axis=-1) / 3
result = 1 - np.ceil(softmask - pfloat1) - softmask * pfloat2
In plain terms: it measures how much each pixel's color agrees with the key color (the dot-product term), compares that to the pixel's overall brightness, and turns the difference into a mask. pfloat1 is the Chroma threshold (default 0.1) - how strongly a pixel must match the key color before it's keyed out. pfloat2 is the Soft Blend (default 20) - a feathering term that makes the mask edge gradual instead of a hard cut. The result is alpha-like: 1 where the color is not the key color (keep), 0 where it matches (remove).
Inputs
imga- your image (tooltip: "image color").imgb- the key color sample (tooltip: "chroma color"). The formula reads a single pixel,imgb[0, 1, 1, :], so a solid-color image (from Contant3Vector) or even a 1×1 swatch works.pfloat1- Chroma threshold, 0–1.pfloat2- Soft Blend, 0–100.
One IMAGE output - the alpha mask.
Install
ComfyUI Manager → search "FuncAsTexture", or:
cd ComfyUI/custom_nodes
git clone https://github.com/CoiiChan/ComfyUI-FuncAsTexture-CoiiNode
# restart ComfyUI
No models, no requirements.txt. Category: FunctionAsTexture.
Where people get burned
- It outputs a mask, not a composited cutout. The result is the alpha you'd use to cut - you still need to multiply your image by it (or feed it as a mask input elsewhere). Expect to wire the result into a mask slot, not straight to a preview.
- The key color comes from one sampled pixel. Point it at an impure color and the key will miss. Use a clean, flat swatch - that's why Contant3Vector exists in this pack.
- Tune the threshold, then the soft blend. Threshold too low keys out half your image; too high leaves a halo of the backdrop color.
pfloat2is a coarse feather, not a precise edge control - this is a simple keyer, not Nuke.
It's the pack's nod to the compositing crowd, and as simple keyers go it's honest: reference color in, alpha out, two knobs. For the "I need a mask from a colored backdrop" moment, it beats hand-drawing every time.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| formula | STRING | #Choma threshold: pfloat1 #Soft Blend: pfloat2 imgb =imgc + imgb[0, 1, 1, :] chomachannel = np.sum((imga * imgb), axis=-1) softmask = chomachannel - np.sum(imga , axis=-1)/3 result = 1- np.ceil(softmask - pfloat1) - softmask * pfloat2 | — |
| pfloat1 | FLOAT | 0.100–1 | Choma threshold: pfloat1. |
| pfloat2 | FLOAT | 20.000–100 | Soft Blend: pfloat2. |
| imgaopt | IMAGE | image color | |
| imgbopt | IMAGE | chroma color |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |