Image Add Alpha
Turn a mask into real transparency (mind the white/black flip)
- image
- mask
- IMAGE
"Image Add Alpha" takes an RGB image and a mask and outputs a 4-channel RGBA image with the mask baked into the alpha channel. If your workflow keeps stripping transparency - or you're re-attaching a mask that came out of a segmentation model back onto an image - this is the node that puts the hole back in.
ComfyUI is a bit notorious for treating alpha as a second-class citizen: plenty of core nodes load or process images as RGB and silently drop the transparency. This node is the "re-attach" step. Combine it with the pack's Image Remove Alpha and you have a tidy round-trip: flatten to RGB when something demands it, then rebuild the RGBA when something needs it.
How it works
The math is one line: the output's alpha channel is 255 - mask. That inversion is deliberate, and it's the thing to understand. ComfyUI's LoadImage node outputs masks in "white = transparent" convention (it returns 1 - alpha). So this node is built to complete the round trip: load a PNG with transparency, take the mask LoadImage gave you, feed it back in here, and you get the original RGBA back.
That means the polarity matters. If you feed in a mask in the more common "white = my subject" convention, your subject comes out transparent and the background opaque - backwards from what you intended. Feed it LoadImage-style masks (white = transparent area) and the results feel intuitive. This is the #1 way people get confused with this node, and it's straight from the source code's own comment: "mask needs inverting because LoadImage is 1 - mask."
Inputs and output
- image (IMAGE) - the RGB image to get its alpha back.
- mask (MASK) - the transparency, ComfyUI convention.
Output is a single IMAGE in RGBA. If the mask is somehow 3-channel, it quietly uses the first channel.
When you'd reach for it
A typical chain: generate → background removal (say BiRefNet) gives you a mask → you want to save a transparent PNG, or composite onto a colored backdrop, or feed an RGBA into a node that composites layers. The mask-to-alpha step is exactly what this node is. Want to inspect the result? Wire the output into a Save Image and check the PNG's transparency - if the wrong thing is see-through, flip your mask (Image Invert does it) before feeding it in.
Installing it
This ships in the comfyui-common-util pack, so:
cd ComfyUI/custom_nodes
git clone https://github.com/longgui0318/comfyui-common-util
cd comfyui-common-util && pip install -r requirements.txt
Restart after. Or use ComfyUI Manager and search "comfyui-common-util". Note that although requirements.txt only pins opencv-python, the pack imports scipy, scikit-image, and PyWavelets when it loads - if ComfyUI reports the pack missing after install, pip install scipy scikit-image PyWavelets sorts it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |