Nodes/ComfyUI 1hewNodes/Mask to Image
ComfyUI Node

Mask to Image

Turn an invisible mask into a color image you can actually see

By 1hew·Created about a year ago·Updated 8 days ago· 33
Mask to Image
  • mask
  • image
fill_holefalse
white_area_color1.0
black_area_color0.0
output_alphafalse

Masks are the invisible scaffolding of every good ComfyUI workflow, and that's exactly why they're annoying to debug. A MASK tensor has no color, no texture - you can't glance at it in the preview and tell whether your matting actually captured the hair strands. Mask to Image converts a mask into a real image, which fixes the visibility problem and a couple of others: you can save the mask as a PNG, feed it to image-edit models that want an image rather than a mask, or build a colored overlay.

How it works

The node maps mask grayscale values onto a color gradient: black regions get black_area_color, white regions get white_area_color, and - importantly - the in-between values become a gradient, not a hard cutoff. A soft mask stays soft. This is the detail most people miss and it's the right behavior: it preserves the alpha falloff so your downstream preview actually represents the real matte.

The inputs:

  • mask - your input mask, batch-supported.
  • fill_hole - fills enclosed black holes inside mask regions before mapping. Turn it on when your mask has donut holes from a bad matte.
  • white_area_color / black_area_color - the two endpoint colors. Formats are the same as the pack's Image Solid node: grayscale like 1.0 or 0.0, hex #RRGGBB, r,g,b, color names, even single-letter shorthands. Defaults are white and black, which is the boring and correct choice.
  • output_alpha - when on, the output becomes RGBA with the original mask values as the alpha channel, while RGB keeps the color mapping.

Output is a single image (RGB, or RGBA with output_alpha).

Install

Part of ComfyUI-1hewNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Restart ComfyUI. No models, no downloads - this is pure tensor math. As with everything in this pack, a recent ComfyUI is expected because the pack uses the newer v3 node API.

Where you'd actually use it

  • Debugging mattes - map white/black, glance at the result, spot the missing chunk immediately.
  • Mask to image-edit models - several image-edit conditioning stacks want a visible "paint this area" image rather than a raw mask tensor. A mask mapped to a red overlay (white_area_color=red) reads way better than a gray slab.
  • RGBA overlays - output_alpha gives you a cutout-ready PNG-style image straight out of a mask.

Common issues

  • Expecting a hard binary mask - this node does not threshold. If you need a hard cutout, threshold the mask before it lands here.
  • output_alpha gotcha - the alpha is the original mask as-is (not inverted, not the mapped colors). White mask areas are opaque. That's almost always what you want.
  • Invisible output - if black_area_color and white_area_color are both 0.0 (or both the same), your "image" is a solid color. The defaults are fine; don't overthink the colors.

It's a simple node, but it's the one you'll keep reaching for the first time you can't tell why your inpaint region looked wrong. Seeing the mask as an image fixes half those debugging sessions instantly.

Category1hewNodes/conversion

Inputs (5)

NameTypeDefaultDescription
maskMASK
fill_holeBOOLEANfalse开启后会先填充 mask 内部封闭黑洞,再进行颜色映射。
white_area_colorSTRING1.0mask 白色区域映射到的颜色;输入格式与 Image Solid 的 color 一致。
black_area_colorSTRING0.0mask 黑色区域映射到的颜色;输入格式与 Image Solid 的 color 一致。
output_alphaBOOLEANfalse开启后输出 RGBA,RGB 仍保持黑白区域颜色映射,同时使用原始 mask 作为 alpha 通道。

Outputs (1)

NameTypeDescription
imageIMAGE