Nodes/ComfyUI-off-suite/Safe Mask to Image
ComfyUI Node

Safe Mask to Image

Preview a Mask Without Blowing Up the Graph

By Off-Live·Created 3 years ago·Updated 2 years ago· 0
Safe Mask to Image
  • mask
  • image
  • IMAGE

Masks are invisible by default in ComfyUI - they're grayscale tensors, and half the downstream nodes won't even accept them. This node converts a MASK into a viewable IMAGE, so you can actually see what your mask looks like before you commit it to an inpaint pass. The "Safe" in the name is the point: if the mask is missing or empty, it hands you a black image instead of crashing the queue.

It's part of ComfyUI-off-suite, and it's one of those boring utilities you stop noticing - which is exactly what a preview node should be.

What you plug in

  • mask - the MASK to visualize.
  • image - a reference IMAGE, used only to size the fallback.

Output is a single IMAGE. Mechanically, the node reshapes the mask to a batch of single-channel frames, then expands each to three channels - so a mask that was 1 channel becomes an RGB image with the mask value repeated across R, G and B. White where the mask is white, black where it's empty. If the mask input is None, it returns a black image sized like your reference image instead.

The "safe" behavior, decoded

That fallback is the whole personality of the node. In a pipeline where a detector occasionally finds nothing (no faces, no objects), your mask can come back empty - and a chain of image nodes downstream would normally throw on a zero-size or missing tensor. This node swallows that failure and gives you a black frame, so the rest of the graph keeps running and you see the problem instead of watching a queue error. It's the mask equivalent of a fuse.

The practical tradeoff: a black output can silently mean "no mask," and if you're not looking, that black image flows into your inpaint encode and produces a no-op inpaint. For a debug/preview node that's the right failure mode - visible, non-destructive.

Where it fits

  • Previewing masks before an inpaint: wire your SAM or bbox-derived mask through this and into a preview node, and you can verify the mask actually covers the face before you spend a sampling pass on it.
  • Feeding masks into image-only nodes: some nodes (image comparisons, certain compositors, text-to-image previews) accept IMAGE but not MASK. This is the adapter.
  • Debugging mask pipelines: when the mask is wrong, seeing it is half the diagnosis. Safe Mask to Image is how you see it.

It pairs naturally with the rest of the pack's mask family - CalcMaskBound (box around the mask), Dilate Mask for Each Face (per-face masks), VAE Encode For Inpaint V2 (the actual inpaint encode) - all of which produce masks you'll want to eyeball through this node before trusting them.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/Off-Live/ComfyUI-off-suite
# or: ComfyUI Manager → search "ComfyUI-off-suite"

No dependencies, no models. ComfyUI's built-in Mask to Image node does the same conversion for well-formed masks - this one just adds the crash-proof fallback. If you never hit the empty-mask case, either one works; if you've been burned by a dying queue, the "safe" version earns its name.

CategoryOFF

Inputs (2)

NameTypeDefaultDescription
maskMASK
imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE