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

Convert Image to Mask

Pull one channel out of an image and call it a mask

By Comfy-Org·Created 4 years ago·Updated about an hour ago· 129,820
Convert Image to Mask
  • image
  • MASK
channel

Convert Image to Mask takes an image and rips out a single channel - red, green, blue, or alpha - as a mask. It's the reverse of MaskToImage and the answer to a recurring question: "I have this image that is my mask, how do I get ComfyUI to treat it as one?" If you've ever loaded a mask image and stared at it, this is the node that finishes the job.

Why you'll reach for it

Masks and images are separate types in ComfyUI - a mask is one channel, an image is three - and not everything that looks like a mask arrives as one. The classic case is a mask you made in another tool: a selection saved as a PNG, a black-and-white silhouette exported from DaVinci or Nuke for video work, an alpha channel from a cutout. Those load as images. ImageToMask converts them.

The channel selector is where it gets useful beyond the obvious. Choosing alpha pulls the transparency channel - so a PNG with a transparent background becomes a mask directly, which is the standard bridge for background-removal pipelines that output transparency rather than a mask. Choosing red, green, or blue grabs that channel as a grayscale mask, which lets you do things like threshold a colorized segmentation image, or lift a luma-like signal out of a single channel when the other channels are noise. People doing color-keying pipelines often end up here as a step.

How it works

The mechanism is a plain tensor index: the image is [B,H,W,3] (or [B,H,W,4] with alpha), and the node does image[:, :, :, channels.index(channel)]. The selected channel becomes a [B,H,W] mask. No thresholding, no normalization, no smoothing - you get exactly the channel's values, in whatever range the image carries (typically 0.0–1.0 after decoding).

The inputs and outputs

  • image - the input image.
  • channel - the dropdown: red, green, blue, or alpha.

One output, MASK. From there it wires into anything a mask feeds: an inpaint encoder, a composite, or a threshold node to clean it up.

Getting it

Core ComfyUI, nothing to install. It lives in comfy_extras/nodes_mask.py with the rest of the mask family.

Where people get burned

  • Alpha doesn't exist on every image. If your image has no fourth channel - which is most decoded photos, and the default output of many loaders - picking "alpha" will error out or hand you nothing. The safe habit: if you loaded an image with transparency, alpha is a great choice; if you're not sure, use red/green/blue, or grab the alpha from LoadImage's separate MASK output instead.
  • A hard-edged mask image stays hard. This node does no thresholding or feathering. A noisy greyscale "mask" comes through noisy. If you need clean white/black, chain ThresholdMask after it.
  • It won't fix polarity. If your mask image has white meaning "keep" and your sampler wants white meaning "regenerate," that's InvertMask's job, one node downstream.
Categoryimage/mask

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
channelCOMBO4 options: red, green, blue, alpha

Outputs (1)

NameTypeDescription
MASKMASK