Nodes/ComfyUI-Light-Tool/Light-Tool: Mask Background to Transparent
ComfyUI Node

Light-Tool: Mask Background to Transparent

Turn a mask into a real transparent cutout (white = kept)

By ihmily·Created 2 years ago·Updated 4 months ago· 20
Light-Tool: Mask Background to Transparent
  • image
  • image

The bridge between "I have a mask" and "I have a transparent PNG" is a specific little operation: put the mask in the alpha channel. Light-Tool: MaskImageToTransparent does exactly that. Feed it a black-and-white mask image and you get back an RGBA image where the white areas are opaque and the black areas are fully transparent. It's the node that converts a mask into a compositable asset.

One input: image. One output: image (RGBA).

How it works. The image is converted to grayscale, then that single channel is used twice: as the RGB content and as the alpha channel. White pixels (255) become fully opaque, black pixels (0) become fully transparent, and everything between becomes partial opacity - so soft-edged masks keep their feathering rather than snapping to hard edges. That's the nice part of the design.

The two things that will trip you up.

  • Convention: white = kept. If your mask is inverted - white background, black subject, which is how a lot of background-removal outputs come - this node will make the background opaque and the subject invisible. Flip it first with the pack's InvertMask (or adjust at the source) and you're back on track. Convention mistakes here are silent and look like "the image vanished."
  • It destroys color. The output's RGB is the grayscale version of the input, not the original colors. This node is designed for masks-as-images, where the input genuinely is a black-and-white mask. If you feed it a color photo thinking it'll cut out the subject by brightness, you get a gray silhouette cutout - it will not extract the subject's real colors. For actual subject extraction from a color image, you want the classic ImageMaskApply / RGB-to-RGBA path in this pack, which uses a separate mask over the true colors.

When you'd reach for it. When a pipeline hands you a mask as an image - a painted mask, a thresholded cutout, a mask you loaded from disk - and the next step needs an actual RGBA asset. Overlay it on a background with ImageOverlay (or simply paste it), export it, or feed it to a node that expects transparency. It's the inverse-ish companion to the pack's ImageToMask, which pulls a channel out of an image.

Installing. With the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/ihmily/ComfyUI-Light-Tool.git
pip install -r requirements.txt
# restart ComfyUI

Or ComfyUI Manager → search ComfyUI-Light-Tool → Install. No models; pure Pillow.

Simple enough that the only real skill is remembering it treats brightness as alpha and white as kept. Get those two conventions right and it's a genuinely useful one-node bridge from mask to cutout.

CategoryComfyUI-Light-Tool/image/mask

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE