Nodes/ComfyUI/Convert Mask to Image
ComfyUI Node Runs on cloud

Convert Mask to Image

The bridge for nodes that refuse to talk to masks

By Comfy-Org·Created 4 years ago·Updated 20 days ago· 121,575
Convert Mask to Image
  • mask
  • IMAGE

Convert Mask to Image does exactly one dumb, indispensable thing: it turns a mask (the [B,H,W] float tensor that says "regenerate here") into a proper image (the [B,H,W,3] RGB tensor) so you can feed it to anything that refuses to accept a mask. It's the plumbing node of the mask world - unglamorous, two seconds to understand, and you'll reach for it every time a custom node or a model input demands an image where you only have a mask.

Why you'll reach for it

ComfyUI keeps masks and images as separate data types, and they are not interchangeable. A mask is one channel; an image is three. The moment you want to do something visual with a mask, you hit the wall: upscalers want images, some ControlNet preprocessors want images, IP-Adapter wants images, and a whole class of third-party nodes will flatly refuse a MASK input. MaskToImage is the adapter.

The most common real use is inspection. ComfyUI has a built-in MaskPreview node now, but previewing a mask as an image - feeding it to a regular image preview, saving it to disk, or passing it into an upscaler that only speaks IMAGE - is the workflow that keeps this node alive. It's also the honest way to see what your mask actually looks like when a mask preview isn't available: white is 1.0 (the region that will be regenerated), black is 0.0.

How it works

The mechanism is trivial and it's worth knowing because it explains the output. The mask is reshaped to [B,1,H,W], moved to a trailing channel, then the single channel is expanded to three identical channels. So what you get is a grayscale image where every RGB pixel is the same value: the mask value. White = 1.0, black = 0.0, and every grey in between. There's no alpha channel, no color mapping, no normalization - it's literally the mask stamped into RGB.

The inputs and outputs

One input, mask. One output, IMAGE. That's the entire node. Connect a mask in, get a grayscale image out, wire it wherever an image is required.

Getting it

Ships with ComfyUI core, nothing to install. It lives in comfy_extras/nodes_mask.py, same file as the whole built-in mask family, and it's been part of core since the mask nodes first existed.

Where people get burned

  • It's grayscale, always. Some people expect the node to colorize or encode the mask somehow. It doesn't - three identical channels, that's the whole deal.
  • Inverting is a separate step. If you preview a mask and think "I wish the white and black were swapped," you don't reach for this node - you put InvertMask before it.
  • Don't use it to "save" a mask. If your goal is keeping a mask for later, mask-to-image then image-back-to-mask round-trips fine because masks are just greyscale - but the correct move is usually just leaving the MASK wire in place. Convert only when a downstream node forces you to. The mask type is lighter, and every unnecessary image conversion is a place for a dtype or device mismatch to creep in.
Categoryimage/mask

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE