图片加遮罩
Burn a mask into an image's alpha channel so composites don't fight you
- image
- mask
- IMAGE
ImageAddMask (图片加遮罩, "add a mask to an image") takes an image and a mask and bakes the mask into the image's alpha channel. Output: a single IMAGE that carries both - RGB from the image, alpha from the mask. It's the kind of node you don't think about until a composite step starts ignoring your carefully-built mask and you realize the graph needed the mask inside the image the whole time.
The direction is worth noting: a white region in the mask becomes transparent, a black region stays opaque. So if your source mask marks the subject in white, this node's output will have the subject punched out of the alpha - which is the standard "cutout" orientation. If that's backwards for your workflow, invert the mask before feeding it in; the node itself won't second-guess you.
How it works
It converts the input to RGBA if it isn't already, then writes the (inverted) mask values into the alpha channel. If the mask is a different resolution than the image, it silently resizes the mask to match before writing - a small mercy that saves you an explicit resize node. Everything else passes through untouched: no blur, no feathering, no threshold. You bring the mask; it just attaches it.
The inputs and the output
- image (IMAGE) - the RGB content you're keeping.
- mask (MASK) - the grayscale mask to convert into alpha. White → transparent, black → opaque, with the resize handled for you.
Output: IMAGE (now RGBA). Wire it into a composite node, a save with alpha, or anything that consumes alpha-bearing images.
Install
Same pack, no special dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam
and restart. No models, no patch. One of the genuinely low-friction nodes in the pack.
Common issues
- Subject is transparent when it should be opaque - the mask's polarity is inverted relative to what you expected. Invert the mask (or the alpha) and re-run.
- Soft edges become hard cutouts - because there's no feathering, the alpha is exactly the mask's values. Feather the mask upstream if you want softer edges.
- Composite looks wrong after "alpha" was added - make sure the downstream node actually reads alpha. Some nodes assume opaque RGB and ignore the channel entirely.
It's a one-job node, but it's the job that makes "mask a thing, then composite it" work as a single image type instead of two. Keep it on the shelf next to ImageToMasks and the pack's crop nodes.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |