Nodes/MTB Nodes/Image Premultiply (mtb)
ComfyUI Node Runs on cloud

Image Premultiply (mtb)

Glue a mask onto an image as its alpha channel

By melMass·Created 3 years ago·Updated about a month ago· 721
Image Premultiply (mtb)
  • image
  • mask
  • RGBA
invertfalse

You've got an image and a separate mask, and you want them married into one RGBA image with real transparency - so you can save a cutout PNG or drop it into a compositing chain. That's what Image Premultiply does. It attaches the mask as the alpha channel and premultiplies the RGB by it.

In ComfyUI, images and masks live as separate things. An IMAGE is RGB; a MASK is a lone channel. Plenty of nodes will happily ignore an alpha channel you think you have. This node is the little bridge that fuses the two into a proper RGBA, which is the format you actually need if you're exporting transparent PNGs or feeding a compositor.

How it works

"Premultiply" means each RGB channel gets multiplied by the alpha before the alpha is attached. So a pixel that's 50% transparent has its color values halved. This is premultiplied alpha, the format most compositing math expects - it avoids the bright or dark halos you get around edges when a compositor blends straight (non-premultiplied) alpha incorrectly. The mask becomes the alpha; the RGB gets scaled to match.

The inputs and outputs that matter

  • image (IMAGE) - your RGB.
  • mask (MASK) - becomes the alpha. White stays opaque, black goes transparent.
  • invert (default false) - flips the mask first. If your subject vanishes and the background stays, tick this.

Output is RGBA (IMAGE) - an image carrying the alpha. Save it as a PNG for a transparent cutout, or send it into a blend/composite node.

How to install it

Via ComfyUI Manager: search MTB Nodes, install, restart. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/melMass/comfy_mtb

then restart. Pure Python, no models, loads with the base pack.

Common issues & troubleshooting

Dark fringes around the edges. That's the "premultiplied" part doing exactly what it says, and it bites when the next node expects straight (non-premultiplied) alpha. If your composite has muddy dark edges, the mismatch is premultiplied-vs-straight - either use a compositor that expects premultiplied, or attach the mask without premultiplying (some workflows just use a Join Image with Alpha node instead).

The alpha silently disappears downstream. A known ComfyUI gotcha: not every node preserves an alpha channel - some quietly drop it and hand you RGB again. If transparency evaporates two nodes later, one of those nodes ate it. Keep the RGBA path short and save it before anything can strip it.

Wrong region is transparent. Use invert. Half the masks in the wild come out flipped.

Categorymtb/image

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
invertBOOLEANfalse

Outputs (1)

NameTypeDescription
RGBAIMAGE