ComfyUI Node

Smart Get Mask

Turn alpha into a mask — mind the inversion

By slvslvslv·Created about a year ago·Updated 25 days ago· 2
Smart Get Mask
  • image
  • MASK

Masks and alpha channels are close cousins, but ComfyUI treats them as different data types: a mask is a single-channel 0–1 plane with no RGB, while alpha lives tucked inside an RGBA image. If you've got a transparent-background image and want a mask you can feed into an inpaint node, a blur, or a crop, Smart Get Mask extracts it for you. It's the "give me the alpha as a MASK" adapter.

How it works

It reads the alpha channel of each image and outputs it as a mask tensor with the batch dimension intact. There's a convention baked in that trips people up, so read carefully: transparent areas come out as 1.0 (white), opaque areas as 0.0 (black) - the mask is inverted relative to alpha. That's actually the standard ComfyUI mask convention for "what to edit" (1.0 = the region of interest), so it's a deliberate choice, but if you wire it into something expecting the subject to be white, you'll get the background selected instead. That's a one-node Invert Mask away from the other orientation.

For plain RGB images with no alpha, it returns an all-white mask (everything opaque). That's a sensible default, though it means "get the mask of an RGB image" silently gives you a full-frame mask - you may want to look twice if you expected something meaningful.

Inputs and outputs

  • image - the IMAGE to extract from. RGBA gives you a real mask; RGB gives you an all-white one.

Output: a single MASK in [batch, height, width] form.

Installing it

From the ComfyUI-SmartImageTools pack:

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

Restart ComfyUI, or install via ComfyUI Manager ("SmartImageTools"). Pure numpy, no extra install weight beyond the pack.

When to use it

Any time a downstream node wants a MASK and all you have is a cutout: feed the output of SmartBackgroundRemove in, get the background-as-mask out, and drive an inpaint or a region-based op. Just keep the inversion in mind - if your masks come out "backwards," that's not a bug, it's the convention. Pair with an invert node and you've got both orientations covered.

CategorySmartImageTools

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
MASKMASK