ApplyMaskToAlpha
Turn a mask into real transparency — the alpha enabler
- image
- mask
- image
A mask and an alpha channel are the same idea in different clothes: a mask says "these pixels are the subject," alpha says "these pixels are transparent." ApplyMaskToAlpha is the bridge - it takes your image and your mask and burns the mask into the image's alpha channel, producing a true RGBA image with real transparency. If you've done background removal and ended up with a mask, this is the node that turns it into an actual cutout you can composite.
Its most important relationship is with the pack's own Area Based Scale (Pixel) node, which counts opaque pixels to do its math. That node needs a real alpha channel, not a mask, and ApplyMaskToAlpha is the documented step for making one - the README is explicit: unless you've got genuine alpha information already, run your image through ApplyMaskToAlpha before feeding it to Area Based Scale (Pixel).
How it works
Three inputs, one output:
- image - what gets the transparency applied.
- mask - becomes the alpha channel. White areas of the mask = opaque, black = fully transparent.
- invert_mask - flips that relationship (black = opaque) when you want the opposite.
The node handles the fiddly bits for you: if the mask isn't the same size as the image it resizes it (LANCZOS, which is the good resampler), and it converts an RGB image to RGBA before writing the alpha in. Output is a single image - now with four channels.
Install
Part of ComfyUI-WBLESS:
cd ComfyUI/custom_nodes
git clone https://github.com/LaoMaoBoss/ComfyUI-WBLESS
restart ComfyUI, or search "ComfyUI-WBLESS" in ComfyUI Manager. No models, no dependencies.
Troubleshooting
Two traps, and both are about other nodes, not this one. First, a lot of ComfyUI downstream nodes treat images as RGB and silently drop the alpha - save with a Save Image node that respects RGBA, or composite the result before it hits anything that flattens it. Second, transparency is fragile: a preview might show the image fine while the alpha was already stripped somewhere upstream, so check the pipeline between this node and your save. invert_mask backwards? That's the number-one wrong-output cause, and it's one toggle. If you're building the alpha pipeline for Area Based Scale (Pixel), this is the node that makes that whole workflow work - feed it a good mask and the pack's pixel-math nodes suddenly have something real to count.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | 要应用遮罩的输入图像 | |
| mask | MASK | 作为透明度使用的遮罩 | |
| invert_mask | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |