Nodes/ComfyUI-multiple-inputs/Multiple Masks to RGB Image
ComfyUI Node

Multiple Masks to RGB Image

See All Your Masks at Once, in Color

By judian17·Created 9 months ago·Updated 9 months ago· 7
Multiple Masks to RGB Image
  • mask_1
  • mask_2
  • mask_3
  • image
  • color_info
inputcount3
binarizefalse
binarize_threshold0.20
remove_noisefalse

Masks are invisible, and that's the whole problem. ComfyUI previews them as grey blobs, so the moment you're juggling three or four of them - a subject mask, a background mask, a couple of inpaint regions - you genuinely cannot tell which is which by looking. Multiple Masks to RGB Image exists to fix exactly that: it takes up to a hundred masks, paints each one in its own distinct color, and hands you a single visual image you can actually read, plus a text legend saying which color belongs to which mask.

If you've ever spent twenty minutes trying to figure out why an inpaint region was bleeding into a neighboring area, you already know why this node earns its keep.

How it works

Each mask gets assigned a color from a fixed palette that starts with pure red, green, blue, then works through brighter, more distinguishable shades. All masks are resized to match your first mask's dimensions (that's what the tooltip on mask_1 is telling you), and each one is painted onto a black canvas - where two masks overlap, the later mask wins.

Two cleaning options ride along, both from the author's tooltips:

  • binarize - turns soft grey mask edges into hard black/white edges, using binarize_threshold (default 0.2) as the cutoff: pixels brighter than the threshold become 1, darker become 0. Great when your mask came from a blurry source and you want a clean silhouette before visualizing.
  • remove_noise - uses scipy's connected-component labeling to drop small isolated pixel islands (dust flecks) under 25 pixels. Handy for tidying up noisy segmentation output.

The palette maxes out at 124 colors, so inputcount caps at 100 - plenty for anything real.

The inputs that matter

  • inputcount - how many masks, up to 100. Change it and click "Update inputs" to actually create the extra mask_N ports.
  • mask_1 - the base mask; every other mask is resized to match its size.
  • binarize and binarize_threshold - toggle hard edges and set the threshold.
  • remove_noise - toggle the dust-cleaning pass.

Outputs are image (the colored composite) and color_info - a string listing every color used, in both RGB and hex form, so you can look at a magenta region and know it's mask number four without guessing.

Installing it

This is one of four nodes in judian17/ComfyUI-multiple-inputs, so install once and you get all of them:

cd ComfyUI/custom_nodes
git clone https://github.com/judian17/ComfyUI-multiple-inputs
cd ComfyUI-multiple-inputs
pip install -r requirements.txt

Or search "ComfyUI-multiple-inputs" in ComfyUI Manager and restart. The dependency list is just numpy and scipy - no models. Look under MyTemplate for all four nodes.

Gotchas worth knowing

The "Update inputs" button is mandatory - bump inputcount and forget it, and your extra mask ports silently don't exist. Also keep binarize_threshold in mind: 0.2 is fine for masks that are mostly white-on-black, but if your mask is faint, raise it or you'll erase half the region.

Wire the color_info output to a Show Text node and you've got a permanent legend for whatever workflow you're debugging. It's a simple node, but it turns mask debugging from archaeology into reading.

CategoryMyTemplate

Inputs (7)

NameTypeDefaultDescription
inputcountINT32–100Number of mask inputs. Click 'Update inputs' to refresh ports.
mask_1MASKThe base mask. All other masks will be resized to match this mask's dimensions.
binarizeBOOLEANfalseIf enabled, converts soft mask edges (gray) to hard edges (black/white).
binarize_thresholdFLOAT0.200.01–0.99The pixel value threshold. Pixels brighter than this become 1, darker become 0.
remove_noiseBOOLEANfalseIf enabled, removes small isolated pixel islands (dust/noise) from the mask.
mask_2optMASK
mask_3optMASK

Outputs (2)

NameTypeDescription
imageIMAGE
color_infoSTRING