Nodes/ComfyUI-zyd232-Nodes/Mask Batch Blend
ComfyUI Node

Mask Batch Blend

Add, Max, or Average Them Into One

By zyd232·Created 2 years ago·Updated 3 days ago· 4
Mask Batch Blend
  • masks
  • Result
operation

Every serious workflow ends up with a pile of masks. A face detector gives you one for the eyes, a background-removal node gives you the cutout, your inpaint region is a third - and half the graph wants a single MASK to composite, inpaint, or weight a conditioning. Mask Batch Blend is the "throw them all in one pot" node: feed it a batch of masks, pick an operation, and get one combined mask out the other side.

It's the sort of node that's boring until the moment you need it, and then it's exactly right.

How it works

The masks input accepts a batch - either a 2D tensor (a single mask, which gets a batch dimension added) or a 4D (batch, 1, height, width) tensor (channel dimension stripped). Then it blends across the batch with one of three operations:

  • add - sums every mask. Overlapping regions get brighter. This is your "overlay" mode, but watch out: values can exceed 1.0 where masks stack, and some downstream nodes don't love that.
  • max - takes the maximum value at each pixel. This is the union: anywhere any mask covers, the result is covered. It's the safest, most forgiving option and the one I'd default to.
  • average - mean of all masks. Great when you want a soft, graduated result from several loose masks.

Edge cases are handled sensibly: a batch of one just passes the mask through, and an empty batch returns an all-zero mask instead of crashing. Both are the kind of defensive behavior you appreciate when a workflow runs at 2am.

The single Result output wires straight into your compositor, inpaint node, mask-to-conditioning, or whichever consumer wants one mask. This slots neatly into the detect → mask → refine loop that masking-detection-detailing describes - detectors hand you many masks, and this is the merge step before the re-render pass.

The practical question: which operation?

The one beginners get bitten by is add. It's labeled "overlay effect" and it does what it says, but it also accumulates - two overlapping 0.7 masks become 1.4, and depending on what's downstream that can read as over-saturated or simply wrong. max is the "keep every region covered by at least one mask" operation and behaves like a union; it's the one I reach for when I want a mask that says "anything any detector found." average is for when you're combining several noisy sources and want the middle ground rather than the maximum.

Install

Same story as the rest of the pack - ComfyUI Manager (search "ComfyUI-zyd232-Nodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/zyd232/ComfyUI-zyd232-Nodes.git

Restart, find Mask Batch Blend under zyd232 Nodes. It's pure torch with no extra dependencies. One caveat: the pack targets ComfyUI's newer V3 backend node API, so a stale ComfyUI install won't register it.

Bottom line

A no-frills utility that does one thing cleanly. If you keep ending up with several masks that all need to feed the same stage, this is a two-input node that dissolves the problem. Just remember max for union, add for accumulation (with the >1.0 caveat), average for softening.

Categoryzyd232 Nodes

Inputs (2)

NameTypeDefaultDescription
masksMASKMasks to blend (supports batches)
operationCOMBOBlend operation: add, max, or average

Outputs (1)

NameTypeDescription
ResultMASK