Nodes/ComfyUI-UniversalToolkit/Image Combine Alpha (UTK)
ComfyUI Node

Image Combine Alpha (UTK)

Stitch a mask into an image's alpha channel in one step

By whmc76·Created about a year ago·Updated 2 months ago· 72
Image Combine Alpha (UTK)
  • RGB_image
  • mask
  • RGBA_image

PNG with transparency is the language of compositing, and getting a MASK tensor into an RGBA image's alpha channel is one of those operations ComfyUI makes weirdly awkward. Image Combine Alpha (UTK) is the two-input, one-output shortcut: RGB image in one port, mask in the other, RGBA image out. That's the whole node, from ComfyUI-UniversalToolkit.

It's a thin utility and it's honest about being one. If you've ever squinted at the built-in channel-split/merge dance just to attach a cutout mask to an image so you can save it as a transparent PNG, this saves you the plumbing. There are no knobs, no mode dropdowns, no settings to get wrong - which is exactly what a node like this should be.

How it works

The mechanism is unglamorous and reliable: it converts the input image to RGB, converts the mask to an 8-bit luminance "L" image, and merges them into an RGBA image via Pillow's Image.merge. The mask's brightness becomes the alpha - white in the mask means fully opaque, black means fully transparent, everything in between is a soft edge. Because it's a straight channel merge and not a matte operation, the RGB pixels are passed through untouched; only the alpha layer is written.

That last point matters more than it sounds. Some "add alpha" nodes premultiply or knock out the background as a side effect. This one doesn't - your RGB stays byte-for-byte what went in, so you can take a mask from a segmentation node, attach it, and save a PNG that composites cleanly on any background later.

Inputs and outputs

  • RGB_image (IMAGE) - the color data.
  • mask (MASK) - becomes the alpha channel.

One output: RGBA_image (IMAGE). Feed it into a Save Image node and pick PNG (or WebP) to keep the transparency. Note the mask is grabbed as-is from the first frame if you feed a batch, so for batch work make sure your mask matches your image count.

Install and gotchas

Install via ComfyUI Manager (search "ComfyUI-UniversalToolkit") or:

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

Restart ComfyUI. No models, no keys, no new heavy deps - this runs on Pillow and torch, both of which you already have.

The one real gotcha is downstream: a lot of ComfyUI nodes silently drop the alpha channel when they process an image, so if you wire RGBA_image into, say, a resize node and the transparency vanishes, that's the resize node's doing, not this one's. Save (or preview via a node that respects alpha) immediately after this node and you'll be fine. If the "transparent" areas come out as solid black, you're almost certainly looking at a viewer or save step that flattened the image - re-check the save settings before you blame the merge.

CategoryUniversalToolkit/Image

Inputs (2)

NameTypeDefaultDescription
RGB_imageIMAGE
maskMASK

Outputs (1)

NameTypeDescription
RGBA_imageIMAGE