Nodes/mm-comfyui-megamask/FlattenAndCombineMaskImages
ComfyUI Node

FlattenAndCombineMaskImages

FlattenAndCombineMaskImages

By meshmesh-io·Created 2 years ago·Updated 2 years ago· 0
FlattenAndCombineMaskImages
  • image
  • IMAGE
count0

FlattenAndCombineMaskImages is the second half of the mm-comfyui-megamask recipe: it collects a bunch of colored mask images and flattens them into one composite. Think of it as the "stack of colored stickers" node. Feed it the frame-by-frame masks of a running person, color-coded by the pack's other node, and it hands you a single image showing the whole motion path at once. That's literally the use case this pack was recommended for on r/comfyui.

But here's the thing you need to know before you wire it in: this node doesn't do anything on its first run. It's a stateful accumulator. It sits in your graph, quietly stacking images, until it's seen exactly count of them - only then does it composite and produce output. If you don't understand that, it just looks broken.

How it works

Each time the graph executes, it appends the incoming image to an internal list. When that list reaches your count, it alpha-composites everything together into one image, returns it, and resets the list for the next batch. It's the "wait until I've seen enough, then merge" pattern - powerful, and easy to trip over.

The inputs that matter

Only two:

  • image (IMAGE) - whatever you're accumulating. The intended partner is ColorListMaskToImage, which colorizes a batch of masks into individual colored images.
  • count (INT, default 0, max 100) - how many images to collect before compositing. This is the trap.

Set count to the number of images you'll feed it. Leave it at the default 0 and the node never matches - you get no output, forever, with no error to explain why.

Installing it

Same pack as its sibling, so one install gets you both:

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

or install "mm-comfyui-megamask" from ComfyUI Manager, then restart. No requirements.txt, no model downloads - it only needs what ComfyUI already ships.

Where people get burned

  • The default count of 0 is a black hole. Set it explicitly, or the node silently waits forever.
  • It remembers between runs. The internal stack doesn't reset until the count matches, so if you re-run a workflow with a different batch size, stale images can linger and a later run composites old data. Change the batch size? Restart ComfyUI to be safe.
  • The alpha-channel problem, which is the real reason people bounce off this pack. The composite math does per-channel alpha blending and expects images that actually carry an alpha channel. ComfyUI core barely produces those - the standard loaders strip alpha - and its sibling ColorListMaskToImage hands you plain 3-channel RGB, not RGBA. So the advertised pairing doesn't line up out of the box. The r/comfyui user who actually tried this pack reported exactly this: alpha images did work, but getting them was so fiddly they gave up and used Impact Pack instead.

That's the honest verdict. For combining RGBA images into one, this works - if it fits, fine. If you're fighting alpha pipelines, Impact Pack's mask handling is the mature path, and Jovimetrix's flatten node exists specifically for this. But if you already have the megamask pack loaded, FlattenAndCombineMaskImages is a zero-dependency way to do it.

Categorymeshmesh

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
countINT00–100

Outputs (1)

NameTypeDescription
IMAGEIMAGE