Nodes/mm-comfyui-megamask/ColorListMaskToImage
ComfyUI Node

ColorListMaskToImage

ColorListMaskToImage

By meshmesh-io·Created 2 years ago·Updated 2 years ago· 0
ColorListMaskToImage
  • mask
  • colorlist
  • background
  • IMAGE

Ever stare at a batch of masks and have no idea which is which? Masks are all white-on-black, so three SAM segments, five inpainting regions, or a stack of video-frame silhouettes look identical in the preview. ColorListMaskToImage is the fix: it paints each mask a different color and hands you a normal RGB image you can actually read.

It's the first half of a two-node recipe from the tiny mm-comfyui-megamask pack (by meshmesh-io). The idea is "megamask": color-code every mask in a batch, then use the pack's other node, FlattenAndCombineMaskImages, to smush them all into one composite. That's how you get the classic "motion path" image of a running person - every frame's silhouette in its own color, all overlaid. The pack is essentially unmaintained (a single commit from March 2024, no README), but for this job it still works.

How it works

Give it a mask - or a whole batch of masks - and it converts each one to a colored image. For every mask in the batch it picks the next color from your list, fills an image with that color, and uses the mask as the alpha channel to composite it over your background. Output is plain RGB, ready for a preview node, a save node, or the flatten half of the pack.

The inputs that matter

Three inputs, and only two of them are interesting:

  • mask (MASK) - your masks, batch or single. Wire in anything that produces MASK: SAM segments, video-frame masks, a MaskFromColor node.
  • colorlist (STR) - a comma-separated list of colors, one per mask, cycling if you have more masks than colors. The person who first recommended this pack on r/comfyui got asked exactly "how do I create a colorlist" - so to save you the same pause: #FF0000,#00FF00,#0000FF. One color works too; everything just comes out that color.
  • background (COLOR, default #000000) - what shows through where the mask is empty.

The only output is IMAGE, so it slots into anything that takes an image: a PreviewImage node, or FlattenAndCombineMaskImages right after it.

Installing it

Standard custom-node install, and it's the lightest one you'll ever do - this pack has no requirements.txt at all, so there are no model downloads and nothing beyond the torch/PIL/NumPy that ComfyUI already ships. Either use ComfyUI Manager (search "mm-comfyui-megamask") or:

cd ComfyUI/custom_nodes
git clone https://github.com/meshmesh-io/mm-comfyui-megamask

Then restart ComfyUI and the two nodes appear under the meshmesh category.

Where people get burned

  • The color rotation is a running counter, not a per-run reset. Re-run the same workflow and masks start cycling from a different color. Cosmetic, but it'll confuse you for a minute if you're diffing outputs.
  • It prints every selected color to your console. Debug prints were left in the source. Harmless noise, worth knowing it's not an error.
  • The composite is only as good as your masks. ColorListMaskToImage fills and composites, it doesn't feather edges - ragged masks give you ragged colored edges. Blur the mask upstream if you want it soft.

Honest take: if you just want to eyeball your masks, a "mask to image" node from Impact Pack or WAS does the same with more polish. But this one's free, zero-dependency, and it's the exact input the pack's combine node was built to eat.

Categorymeshmesh

Inputs (3)

NameTypeDefaultDescription
maskMASK
colorlistSTR
backgroundCOLOR#000000

Outputs (1)

NameTypeDescription
IMAGEIMAGE