Nodes/ComfyUI_BadgerTools/ApplyMaskToImage-badger
ComfyUI Node

ApplyMaskToImage-badger

Turn a mask into an alpha channel

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
ApplyMaskToImage-badger
  • image
  • mask
  • rgba_image

Most ComfyUI masks never become actual transparency. A mask gets fed to a sampler as inpainting context, gets used to blend two latents, gets forgotten. ApplyMaskToImage-badger is the one that does the thing people assume every mask node does: it bakes the mask into the image's alpha channel and hands you back a real RGBA image with true transparency. Export that and you've got a cutout you can drop onto anything.

This is your end of a background-removal pipeline - take the subject mask, apply it, save a transparent PNG. It's also how you'd build a custom compositing asset, or stamp one image onto another without the rectangular JPEG look. The wider inpainting-vs-mask debate has moved on (edit models can regenerate whole images now), but nothing else gives you bit-exact transparency from a mask, which is what this is for.

How it works

The mechanism is refreshingly direct. The image gets converted to RGBA, the mask is read as a grayscale alpha, and PIL composites the two:

  • where the mask is white, the pixel keeps its original alpha (opaque),
  • where the mask is black, the alpha goes to zero (fully transparent).

So a subject mask (subject white, background black) gives you a floating subject. It's a straight alpha bake - no diffusion, no resampling, no clever edge feathering. What you put in is what you get, which is exactly why it's useful.

Inputs and outputs

Only two inputs, both required:

  • image - any IMAGE tensor.
  • mask - a MASK tensor. This is the only thing that matters; get it right and everything else is automatic.

One output: rgba_image (an IMAGE with the alpha channel filled in). Wire it to a SaveImage and check "save as PNG" in the save dialog - PNG is the format that keeps the transparency.

Installing it

It ships in the ComfyUI_BadgerTools pack. Easiest path is ComfyUI Manager: search "BadgerTools" (or the full repo name), hit Install, restart. Or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools
# then restart ComfyUI

No model files to download for this node. One thing to know before you install: the pack's requirements.txt is heavy (moviepy, open_clip_torch, sentence_transformers, scikit-image, three opencv variants), and because the pack imports its video code at module load, ComfyUI drags all of that in on every startup even if you only use the mask nodes. First launch after install can be slow. That's the price of a pack that's one author's personal utility drawer - the README is literally two lines, and it shows.

Gotchas

  • The mask must be the same size as the image. The code doesn't resize either one. If your mask was generated at a different resolution, PIL will choke on the composite. Resize the mask first.
  • It processes one image at a time. Batches other than the first image in the tensor won't come through - keep it on single images.
  • White = keep, black = cut. If your mask is inverted you'll get a transparent hole where the subject was. Flip it and rerun.

The pack has essentially no community footprint - you won't find a thread of people comparing settings, because there's nothing to tune. It's a small honest utility node that does one job without fuss. For a node that can feel like magic in a compositing workflow, that's a compliment.

Categorybadger

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
maskMASK

Outputs (1)

NameTypeDescription
rgba_imageIMAGE