半透明抠图 / Unmult Matting
The mathematically exact way to cut a glow off a black background
- image
- subject_mask
- rgba_image
- alpha
Every neural matting model is guessing. Unmult doesn't guess - it does algebra. 半透明抠图 / Unmult Matting is the After Effects Unmult trick wrapped as a ComfyUI node: if your render sits on a known solid background, the composite equation C = αF + (1−α)B has exactly one solution for the foreground color F and the alpha α, and this node solves it. No model inference, no GPU, and it keeps every bit of the semi-transparency a segmentation network physically cannot represent.
That last point is the real reason you'd reach for it. Glow, fire, smoke, particles, lens flares, UI effects - the whole category of "bright thing on a pure-color background" - comes out with fractional alpha intact, in milliseconds, on a batch of video frames if you want. The README's own reconstruction test shows the math recovers both alpha and foreground color from a known composite with an average error of 0.0000 on black, white, and green-screen backgrounds. It's exact by construction, not by tuning.
Inputs and outputs
- image - the composite to unmult. Accepts batches, so sequence frames run through in one pass.
- bg_color - the background color as
#RRGGBB. Common picks:#000000,#FFFFFF,#00FF00(green screen),#FF00FF(magenta). - 黑点 / 白点 (black point / white point) - two sliders. Below the black point, alpha is forced to zero (kills background noise residue); above the white point, alpha snaps to one (makes the subject solid). The defaults - 0 and 1 - are a pure pass-through.
Outputs: rgba_image (4-channel IMAGE, premultiplied composite ready for compositing) and alpha (MASK) if you want to drive something else with it.
The internals are straightforward: it measures how far each pixel deviates from the background color, normalizes per channel, takes the max as alpha, then solves foreground = bg + diff/alpha. The sliders are just a remap of that alpha before solving.
The trap: black background + dark solid subjects
This is the one that bites. Unmult on a black background is effectively treating brightness as opacity - which is exactly right for a glow and exactly wrong for a solid object. The README shows a solid subject whose true alpha is 1 everywhere: on a black background the bright parts reconstruct at 0.900 alpha but the dark parts (hair, dark clothes, shoes) fall to 0.080 - cut clean through. Same subject on green screen: 0.940 everywhere. So:
- Light effects, fire, smoke, particles, UI elements on pure color → this is the best tool in the pack.
- Green/magenta screens with high contrast against the subject → also great, even for solid subjects.
- Black background + solid character → use Lucida or FeyNobg instead. No amount of slider twiddling fixes a geometry problem.
If you're left with background fuzz after a good unmult, nudge the black point up a little rather than the white point down - that clears residue without hardening the edges that matter.
Installing
Part of RUI-Nodes:
ComfyUI Manager → search "RUI-Nodes" → install, restart
# or:
cd ComfyUI/custom_nodes
git clone https://github.com/rui40000/RUI-Nodes
cd RUI-Nodes && pip install -r requirements.txt
No weights to download - it's numpy math. The ecosystem's habit is to throw a 1GB model at every cutout problem, and this node is the useful counter-example: sometimes the right tool is a formula.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | 待去底的图像,支持批量(序列帧/视频帧逐帧处理)。 | |
| bg_color | STRING | #000000 | 要去除的背景色,#RRGGBB 格式。 常用值:#000000(黑底)、#FFFFFF(白底)、#00FF00(绿幕)、#FF00FF(品红)。 |
| 黑点 | FLOAT | 0.000–0.5 | 低于此值的 alpha 强制归零。 调高可清除背景残留噪点,但过高会丢失边缘细节。 |
| 白点 | FLOAT | 1.000.3–1 | 高于此值的 alpha 强制归一。 调低可让主体更实、减少半透明损失,但过低会让边缘硬化。 |
| 主体保护 | BOOLEAN | true | 是否采纳下方接入的 subject_mask。 启用:alpha 取 max(unmult 结果, subject_mask), 主体区域强制不透明,光效边缘仍保留半透明。 黑底素材里的黑衣、黑发全靠它保住。 关闭:即便已经连了 subject_mask 也完全不采纳, 等同于纯 Unmult。想对比「有无 AI 介入」的差别时, 拨这个开关即可,不必拔线。 |
| subject_maskopt | MASK | AI 主体保护遮罩(可选)。 接入 FeyNobg / Lucida / BiRefNet 等抠图节点输出的 alpha, 节点会执行 max(unmult_α, subject_mask) 合并: 主体内部强制不透明,光效边缘保留半透明。 典型场景:黑底光效中人物穿黑衣 → 纯 Unmult 会让黑衣半透明,接入主体 mask 后黑衣保留。 不连接、或上方「主体保护」关闭时,等同于纯 Unmult,无 AI 介入。 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| rgba_image | IMAGE | — |
| alpha | MASK | — |