ComfyUI Node

YKMaskToImage

When a node wants an IMAGE and you've only got a MASK

By yankeguo-deprecated·Created 3 years ago·Updated 2 years ago· 10
YKMaskToImage
  • mask
  • IMAGE

Masks in ComfyUI are a different beast from images, and it bites everyone eventually. An IMAGE is a [batch, height, width, channels] tensor - a stack of full-color frames. A MASK is just [height, width], one float channel, where 0 is black, 1 is white, and everything between is your soft edge. That's great for conditioning a model, but it's a problem the second you want to do something mundane with a mask, because a huge share of nodes only accept IMAGE: preview nodes, SaveImage, and various attention/conditioning utilities all refuse MASK outright.

YKMaskToImage is the two-line adapter that fixes it. You feed it a MASK and it returns an IMAGE - specifically, the mask values replicated across all three RGB channels so you get a proper grayscale image where white is white and black is black. Look at the entire implementation and it's one tensor operation: add a batch dimension, add a channel dimension, expand to 3 channels. That's the whole node, and that's exactly what you want from glue.

When you'll actually reach for it

The most common case is debugging. You built a mask for an inpaint or outpaint pass, and you want to see it. Drop this node between your mask source and a preview or SaveImage node and suddenly you can eyeball whether your selection actually covers the region you meant, whether the feathering band is where you think it is, and save the mask as a PNG to inspect pixel by pixel. That alone justifies it - the KB's inpainting essay is full of "seams looked wrong, mask was wrong" stories that a 10-second visual check kills instantly.

The second case is feeding a mask to a node that only takes IMAGE. Some ControlNet preprocessing setups, IPAdapter style passes, and assorted third-party utility nodes want an IMAGE input and will throw a type error if you wire a MASK in. This node is the translator.

Inputs, outputs, and honest limits

One input, mask, and one output, IMAGE. There are no parameters to fiddle with, which is either refreshing or a hint that this node does exactly one thing. A couple of things it won't do, so you don't get surprised: it does not invert the mask (that's a MaskInvert, elsewhere), it does not threshold or binarize - soft 0.5 values stay 0.5 grey in the output - and the output is a single frame at batch size 1. If you need a hard black-and-white cut or an inverted selection, you'll want another node in front of it.

Installing it

Same pack, same story as YKImagePadForOutpaint: no dependencies beyond what ComfyUI already has, no models, no config. Via ComfyUI Manager, search "yk-node-suite" under Install Custom Nodes. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/guoyk93/yk-node-suite-comfyui.git yk_node

Restart ComfyUI and the node appears under the "mask" category.

The honest take

This is a three-line node, and you could write the equivalent yourself in an Lora/script custom node in five minutes. That's not a criticism - it's the point. Utility nodes like this are the plumbing that keeps a graph from turning into a jumble of type-mismatch errors, and it costs nothing to have installed. Where you can get burned is reaching for it as a fix-all: converting a mask to an image doesn't make your sampling smarter, it just changes the type. Use it to look at masks, save them, and hand them to IMAGE-only nodes - not as a way to pretend a mask is something it isn't.

Categorymask

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE