Flatten Mask Batch
Collapse a stack of masks into one
- masks
- MASK
A mask batch in ComfyUI is a stack of masks - one per frame, per detection, or per whatever produced them - kept as separate layers rather than merged. Flatten Mask Batch collapses that stack down into a single mask, per the README: "Flattens a Mask Batch into a single Mask." Where a batch of N masks goes in, one mask comes out, combining whatever coverage exists across the whole stack.
You reach for it when something downstream wants exactly one mask and won't take a batch - a single composite step, a node that expects MASK rather than a batched sequence, or when you conceptually just want "everywhere any of these masks covered" as one region.
How it works
The node walks the batch and merges every mask's coverage into one output. The README adds an important caveat worth taking at face value: "Normal operation is not guaranteed for non-binary masks." That's a direct signal about what this node is built for - clean, mostly-binary masks (the kind detectors and threshold operations produce), not soft, gradient, or heavily anti-aliased ones. If your batch has a lot of partial gray values, the flattening behavior isn't guaranteed to do what you'd expect.
The input and output
masks(MASK, required) - the batch to flatten. The plural naming and the batch framing in the README both point to this expecting a stacked/batched mask input rather than a single mask (flattening a single mask would be a no-op).
Output is a single MASK - the collapsed result.
How to install it
Ships with the Impact Pack. ComfyUI Manager: search ComfyUI Impact Pack, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
pip install -r requirements.txt
then restart. No models - pure array operation.
Common issues & troubleshooting
Result looks wrong or muddy. Per the README's own caution, this is expected if your input masks aren't binary. Threshold your masks first - Impact Pack's ToBinaryMask node converts alpha-valued masks into clean 0/255 output - before flattening if you're seeing unexpected results with soft-edged or gradient masks.
Not sure whether you want this or Masks to Mask List/Mask List to Masks. Those two convert between a batch and a Python-style list of individual masks (for iterating one at a time); they don't merge anything. Flatten Mask Batch actually combines the batch's coverage into one mask. Use the list nodes when you want to process each mask separately, and this node when you want them combined.
You wanted to combine two named masks, not a batch. If you're working with exactly two masks from separate sources rather than a batch, AddMask (Pixelwise MASK + MASK) is the more direct tool and doesn't carry the non-binary-mask caveat this node does.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |