Nodes/Masquerade Nodes/Image To Mask
ComfyUI Node Runs on cloud

Image To Mask

Turn a picture (or its alpha) into a usable mask

By BadCafeCode·Created 3 years ago·Updated 2 years ago· 481
Image To Mask
  • image
  • MASK
method

You'll hit this node most often right after loading something that isn't natively a mask but obviously should be one - a black-and-white PNG you painted in an external editor, a segmentation result someone exported as a picture, or an image that already carries transparency where the "masked" area should be. Image To Mask converts a regular image into ComfyUI's proper MASK type so the rest of your graph can actually use it.

There are two ways to derive that mask, and picking the right one matters. intensity reads the grayscale brightness of the image - white pixels become mask value 1, black pixels become 0, and anything in between is proportional. This is what you want for a painted black-and-white mask, or any image where "brightness" is standing in for "how masked is this." alpha ignores color entirely and reads the image's alpha channel instead - useful when you've got a PNG that already has transparency baked in (say, something exported from Photoshop or another tool with the background already cut out) and you want that transparency turned into a mask rather than re-deriving it from pixel brightness.

The inputs that matter

  • image - the image to convert.
  • method - intensity or alpha.

The single output is a proper MASK, in the form the rest of ComfyUI (and the rest of Masquerade Nodes) expects - ready to plug into a sampler's mask input, Cut By Mask, Combine Masks, or anywhere else a mask is called for.

The mistake worth avoiding: using intensity on an image that doesn't actually encode mask information in its brightness. A full-color photo run through intensity will produce a mask, technically - every image has a grayscale interpretation - but it'll be meaningless, just whatever the luminance happens to be at each pixel rather than an intentional selection. This node doesn't validate that your input makes sense as a mask; it trusts you to feed it something that does.

Installing it

Image To Mask ships with the rest of Masquerade Nodes. Install via ComfyUI Manager (search "Masquerade Nodes") or clone it directly: cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart ComfyUI. It's a plain conversion node - no model weights, no extra Python dependencies, nothing to fetch on first run.

Common issues

If your resulting mask looks inverted - masking the thing you wanted to protect instead of the thing you wanted to affect - that's not a bug in this node, it's a sign the source image's brightness or alpha is the opposite of what you assumed. Feed it into Preview Image (or a Unary Mask Op with invert, if you'd rather flip it than fix the source) to confirm before you build the rest of your workflow on top of it. If you're converting a PNG that was supposed to carry transparency and alpha mode gives you a fully opaque (all-1) mask, check that the file actually saved with an alpha channel intact - some export paths flatten transparency into a solid background without warning, in which case there's no alpha data left for this node to read.

CategoryMasquerade Nodes

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
methodCOMBO2 options: intensity, alpha

Outputs (1)

NameTypeDescription
MASKMASK