ComfyUI Node

MaskToImage_AS

Render a mask as a grayscale image so you can actually see it

By flyingshutter·Created 3 years ago·Updated about a year ago· 8
MaskToImage_AS
  • mask
  • IMAGE

MaskToImage_AS converts a MASK into an IMAGE by copying the single-channel mask into all three RGB channels. The result is a grayscale image where white means "mask = 1" and black means "mask = 0". One input, one output, no options - and it's the mirror image (literally) of ImageToMask_AS from the same pack.

It's part of flyingshutter's As_ComfyUI_CustomNodes, a dependency-free playground pack with no models and no installs beyond a clone.

How it works

The mechanism is a simple channel replicate: the mask tensor's single channel is assigned to the red, green, and blue planes of a fresh image tensor, so you end up with an IMAGE where every pixel is gray with a value equal to the mask's value at that spot. Because masks and images live in the same 0–1 range, the conversion is lossless - white stays white, black stays black, and any mid-gray mask value stays mid-gray.

The inputs

  • mask - the MASK you want to visualize or hand off as an image.

Output is an IMAGE. The node also prints the mask's size to the console on every run (a leftover debug print), which is noise but also a quick way to confirm your mask's resolution.

Where you'd use it

Two main jobs. First, previewing: ComfyUI's mask nodes are notoriously invisible in the graph - a mask is just a tensor with no built-in preview, so "is my mask actually where I think it is?" is a real question. This node turns it into something you can attach to a Preview Image node and actually look at. That alone is worth having in your toolkit for any inpainting workflow.

Second, handing masks to image-space tools: some downstream nodes and workflows expect an IMAGE rather than a MASK - say, a compositor that blends by luminance, or a custom node that only takes images. This node is the adapter that lets you reuse a mask you already computed. And if you want to edit a mask in an external editor, you can bounce it to an image, save it, edit it, and convert back with ImageToMask_AS.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes

Restart ComfyUI and it's under ASNodes (or ComfyUI Manager → "As_ComfyUI_CustomNodes"). No extra dependencies.

Common issues

  • Debug print spam. The print("MASK SIZE:", mask.size()) lines fire on every execution. Harmless, but if your console is filling up, this is where it's coming from.
  • Single mask assumption. Like most of this pack, it's written for a single mask/image. Batches can produce unexpected shapes.
  • Expecting color. A mask has no color information - it's inherently grayscale. If you convert a mask to an image and it looks gray, that's correct; color would have to come from elsewhere.

Simple, predictable, and genuinely useful for the one thing that matters - finally seeing what your mask looks like.

CategoryASNodes

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE