Mask Batch Math Ops
Collapse a whole mask batch into one mask — union or intersection
- mask
- mask
You know the scenario: a segmentation pass returns one mask per frame, or one mask per detected region, and what you actually want for the next step is a single mask that says "everything that matters is here." This node collapses an entire mask batch into one mask, using either a logical OR (union - any pixel that's white in any frame becomes white) or AND (intersection - only pixels white in every frame survive).
It sits in the pack's batch-processing group, and it's the mask counterpart to what you'd do with several individual masks and a merge node - except it does the whole batch in one shot, with no manual wiring per mask.
How it works
Feed it a mask batch and an operation:
or(default) - union. It takes the element-wise max across the batch: a pixel is white if any frame marked it white. This is the "merge all detections" mode - combine per-frame masks from a video, or per-region masks from an object detector, into one big "all the stuff" matte.and- intersection. Element-wise min: a pixel stays white only if every frame had it white. Use this when you want only the pixels that were consistently marked, e.g. a stable region across a video where the subject never leaves the frame.
Internally it slices the batch into chunks and reduces each with the max/min op, then combines the chunks - so even a very large batch (hundreds of masks) doesn't blow up memory. Output is a single mask. Single-frame input passes through unchanged.
The outputs wire anywhere a mask goes: into an inpaint region, a background-removal matte chain, a compositor, or further mask math. If your batch came out of a list (not a tensor batch), batch it up first - this node takes a batch, not a list.
Where it earns its keep
Video is the classic case: a per-frame subject mask from SAM or a detector, and you want one mask representing "the subject, across the clip" - for a stable region to inpaint, or to know where the action is. or is your friend there. If instead you're building a mask of "what's the same in all frames" (camera-static regions, backgrounds that don't move), and is exactly that: only pixels consistent across every frame survive.
Installing it
Part of 1hewNodes. ComfyUI Manager → search "ComfyUI 1hewNodes" → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
Restart ComfyUI. No special dependencies, no model downloads.
Common issues
The one that bites: if your "batch" is actually a list of masks from a node like the pack's own Mask Batch to List, this node won't see it - lists and batches are different wire types in ComfyUI. Convert back to a batch first. Also remember the output is a single mask at the same resolution as the inputs; if your input masks were different sizes (possible with mixed sources), the batch itself is already misaligned and the union will be garbage - normalize sizes before collapsing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| operation | COMBO | or | 2 options: or, and |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |