ComfyUI Node

Apply Mask to Image

Bake a mask into an image's alpha channel

By Acly·Created 3 years ago·Updated about a month ago· 667
Apply Mask to Image
  • image
  • mask
  • masked

Small, boring, and exactly what you want when you need it. ComfyUI keeps images (RGB) and masks (single-channel) as separate things flowing on separate wires. ETN_ApplyMaskToImage glues them: it copies a mask into the alpha channel of an image and hands you back a single RGBA image where the mask is the transparency. That's it. That's the node.

Why bother? Because the moment you want to hand a result to something outside ComfyUI - a compositor, a paint app, a web canvas, another node graph - a masked region is far more useful as an image-with-alpha than as two loose wires. This node is part of Acly's ComfyUI Nodes for External Tooling, the pack built for using ComfyUI as a backend for other software (his Krita AI Diffusion plugin most notably), and packaging a cutout as one transparent PNG is precisely the kind of "make it easy to send outward" job the pack is full of.

How it works

You give it an image and a mask of matching dimensions. It takes the mask's values and writes them into the image's alpha channel - white areas of the mask become fully opaque, black areas become fully transparent, and grays give you partial transparency with soft edges. The RGB pixels are untouched; only alpha changes. Out comes an RGBA image you can save as a transparent PNG, send over the pack's websocket/cache nodes, or feed anything that understands alpha.

There's no thresholding, feathering, or blending logic to configure - it's a straight copy of mask → alpha. If you want soft edges, blur the mask before this node with a mask-blur node; the softness carries straight through.

The inputs and outputs that matter

Both inputs are required and there's nothing to tune:

  • image (IMAGE) - the picture whose alpha you're setting.
  • mask (MASK) - the transparency map. Should match the image size; if it came from a segmentation node, a Load Mask, or the region nodes in this same pack, it already will.

One output:

  • masked (IMAGE) - the RGBA result. Wire it into Save Image (you'll get a transparent PNG), or into one of the pack's send-image nodes to ship the cutout to your external tool.

How to install it

Install the whole pack in one go. Via ComfyUI Manager, search ComfyUI Nodes for External Tooling, install, restart. Or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/Acly/comfyui-tooling-nodes.git

then restart ComfyUI. No models, no heavy dependencies - this is a few lines of tensor work.

Common issues & troubleshooting

The alpha comes out inverted. Masks and alpha share a convention here - white/1 is opaque, black/0 is transparent - but plenty of mask sources are inverted relative to what you expect (a "select the subject" mask vs a "select the background" mask). If your subject vanished and the background stuck around, invert the mask upstream and re-run.

Sizes don't match, or the result looks misaligned. The mask needs to be the same resolution as the image. If your mask came out at latent scale (1/8 the image) or from a differently-sized source, resize it to the image dimensions before this node.

The transparency doesn't show up. Make sure you're actually saving RGBA - a plain Save Image will keep the alpha for a PNG, but if you re-encode as JPEG downstream, alpha is silently dropped. Keep it PNG (or send it via the pack's cache/websocket nodes, which preserve the channel).

Categoryexternal_tooling

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
maskMASK

Outputs (1)

NameTypeDescription
maskedIMAGE