Nodes/ComfyUI-YCNodes/Mask Batch Composite
ComfyUI Node

Mask Batch Composite

Staple two mask batches together — despite the name, it's concatenation, not blending

By yichengup·Created 2 years ago·Updated 4 months ago· 47
Mask Batch Composite
  • masks_1
  • masks_2
  • combined_masks

The name says "composite," which suggests blending one mask into another. It doesn't do that. Mask Batch Composite is a one-liner that concatenates two mask batches along the batch dimension: feed it masks_1 (say, 4 masks) and masks_2 (2 masks), and you get one tensor of 6 masks. That's the whole job.

That's still genuinely useful. Mask utilities love to produce one mask per output - per-object, per-frame - and downstream you often need them as a single batch. If you have two nodes that each emit their own set of masks (a face detector and a hand detector, two frame ranges, a split node and a filter node), this is the cheap merge point. Core ComfyUI doesn't have a dedicated "concatenate mask batches" node sitting in the menu, so this fills the gap without pulling in a big suite.

How it works

It's torch.cat([masks_1, masks_2], dim=0) with a shape guard that promotes 2D masks to 3D first. Nothing clever, which is the appeal. No blending, no alpha, no weighting - the output is a strictly bigger batch.

The inputs that matter

Both of them, and there are only two: masks_1 and masks_2, each a MASK. The output is combined_masks, order preserved: first batch's masks, then second's.

The constraint that matters: torch.cat requires matching dimensions on every axis except the one you're joining. So both inputs must have the same height and width. If they don't, you'll get a runtime error - resize or pad one side to match before merging. This is the single thing that trips people up, because it's the one place the node can't help you.

Install

Ships in ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes

Restart ComfyUI. Standard deps only (torch, numpy, pillow, opencv-python, scipy), no models. It sits under "YCNode/Mask/Batch" in the menu, next to its siblings Mask Batch Copy, Mask From Batch, and Mask Repeat Batch - that little batch-mask family is really one idea in four variants, and this is the merge end of it.

Gotchas

Beyond the size-matching rule, one subtlety: this joins batches. If you want to union two masks into one combined region (a single mask covering both), this is the wrong tool - you want a boolean-op composite like Mask Composite YC from the same pack, or core's MaskComposite/ImageCompositeMasked. It's an easy mix-up because the names are one letter apart. And there's no way to control ordering or dedupe; it's strictly append.

CategoryYCNode/Mask/Batch

Inputs (2)

NameTypeDefaultDescription
masks_1MASK
masks_2MASK

Outputs (1)

NameTypeDescription
combined_masksMASK