Nodes/Node_Fun_ComfyUI/BW to Mask / Alpha
ComfyUI Node

BW to Mask / Alpha

Turn any black-and-white image into a real mask (plus RGBA) — no second node needed

By nofunstudio·Created 2 years ago·Updated 2 months ago· 9
BW to Mask / Alpha
  • image
  • mask
  • rgba
invertfalse

You hand-painted a mask in Photoshop, exported it as a grayscale PNG, and dragged it into ComfyUI expecting your inpainting to honor it. Then you stared at the graph wondering why nothing changed. This is the node that fixes that specific moment. BW to Mask / Alpha (class BWToMaskAlpha) takes a black-and-white image and converts it into a proper MASK tensor, and it also hands you an RGBA version where black is transparent. The invert toggle is baked in, so you don't need a separate Invert Mask node cluttering the graph.

How it works

The mechanism is refreshingly simple. The node reads the luminance of your image - weighted as 0.2126 R + 0.7152 G + 0.0722 B - clamps it to 0–1, and uses that as the mask. White keeps, black discards. Flip invert and you get the opposite: 1 − mask, so black becomes the keep region. Mid-gray stays mid-gray, which is exactly what you want for feathered edges.

The rgba output keeps your original RGB pixels and stamps the mask onto the alpha channel. Black areas render transparent; white renders opaque.

Inputs and outputs that matter

There are only two inputs, and you'll set one of them:

  • image - your grayscale mask. It can be any image, not just truly black-and-white; the luminance blend handles soft gradients fine.
  • invert - boolean, off by default. Flip it when your mask is white=discard instead of white=keep.

Outputs:

  • mask (MASK) - wire this into a KSampler (Advanced) via its denoise mask, or into VAE Encode for masked inpainting.
  • rgba (IMAGE) - feed this to an Image Composite Masked, or save it as a PNG/WEBP with alpha for downstream work.

Where it sits in a workflow

This is a prep node. The classic chain: Load Image (your mask) → BWToMaskAlpha → mask into your inpainting sampler. Or use the rgba output for compositing layers. It's also handy for turning text or logo art into a transparency for overlays.

Gotchas

  • It reads luminance, not alpha. If you feed a PNG that already has transparency, that alpha channel is ignored - the node only looks at RGB. For that job, use ComfyUI's core Image To Mask with the Alpha channel instead.
  • JPEG masks are soft masks. Compression smears hard edges into gray mush, and gray means partially masked. Save your masks as PNG.
  • Beyond that there's nothing to trip on - no API, no model download, no dependencies beyond torch.

Install

In ComfyUI Manager, search Node_Fun_ComfyUI, or:

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

Then restart ComfyUI. It's a small MIT-licensed pack, and this node in particular carries almost no surface area - worth having in your back pocket even if you never touch the pack's API nodes.

Categorymask

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
invertBOOLEANfalse

Outputs (2)

NameTypeDescription
maskMASK
rgbaIMAGE