Mask to Image
Turn an invisible mask into a color image you can actually see
- mask
- image
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 Solidnode: grayscale like1.0or0.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_alphagives 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_alphagotcha - 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_colorandwhite_area_colorare both0.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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| fill_hole | BOOLEAN | false | 开启后会先填充 mask 内部封闭黑洞,再进行颜色映射。 |
| white_area_color | STRING | 1.0 | mask 白色区域映射到的颜色;输入格式与 Image Solid 的 color 一致。 |
| black_area_color | STRING | 0.0 | mask 黑色区域映射到的颜色;输入格式与 Image Solid 的 color 一致。 |
| output_alpha | BOOLEAN | false | 开启后输出 RGBA,RGB 仍保持黑白区域颜色映射,同时使用原始 mask 作为 alpha 通道。 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |