Nodes/Vevor Mask Union/Mask Batch Union (regions → 1)
ComfyUI Node

Mask Batch Union (regions → 1)

Why Your OCR Mask Needs A Union Node

By rexqin·Created about a month ago·Updated 19 days ago· 0
Mask Batch Union (regions → 1)
  • mask
  • mask

You run an OCR node over a listing image, it finds 22 text regions, you feed the mask into ImageCompositeMasked - and exactly one region gets re-rendered. No error. No warning. The other 21 are still sitting there in the original pixels and you spend twenty minutes convinced your denoise is too low.

That's the whole reason this pack exists, and VevorMaskBatchUnion is the node the repo is named after. It's also the only one its README actually explains, which tells you something about how the pack grew.

What it actually does

One input, one output, zero widgets: MASK in, MASK out. The entire implementation is torch.amax(mask, dim=0, keepdim=True) - the per-pixel maximum across the batch, which for a 0/1 mask is a logical OR. Every region that was white in any frame is white in the output.

That sounds like a two-line job because it is a two-line job. The value is knowing it's missing. OCR nodes in the EasyOCR lineage emit masks as a batch with one full-size frame per detected region: frame 0 is white only inside box 0, frame 1 only inside box 1, and so on. That's a perfectly sensible output shape and it's a trap, because two core nodes look like they should merge it and don't.

MaskComposite throws The expanded size of the tensor (1) must match the existing size (N) the moment you hand it two masks with different batch sizes. ImageCompositeMasked is worse - it calls repeat_to_batch_size on the mask, which slices the batch down to the destination image's batch size. Give it one image and it keeps frame 0, throws away the other 21, and composites happily. Silent, non-erroring, wrong.

The inputs and outputs

mask - the MASK socket. Wire it straight out of the OCR node's mask output.

And that's it, which is why the interesting behaviour is in what the node does with odd inputs rather than in its parameters. Read from the source, three pass-through cases matter:

  • A 2D (H, W) mask just gets a batch dimension added - nothing to union.
  • A single-frame batch comes back untouched.
  • An empty batch (0, H, W) comes back as an empty batch. The author is explicit about why: with zero frames there's no size information left to rebuild a frame from. Practically, this is your "OCR found nothing" signal - see below.

Output is a normal MASK, so it goes into GrowMask, FeatherMask, ImageCompositeMasked, a masked latent, whatever.

Install

ComfyUI Manager, search the pack title Vevor Mask Union, or:

cd ComfyUI/custom_nodes
git clone https://github.com/rexqin/comfyui-vevor-mask-union
# restart ComfyUI

The pack's pyproject.toml declares dependencies = [], and this node needs nothing beyond torch, which ComfyUI already ships. The heavier nodes in the same pack (PaddleOCR) are opt-in pip installs. Nothing to download to use this one.

The node shows up in the node search under Mask Batch Union (regions → 1), category vevor/mask.

Wiring

The order matters more than people expect:

Apply EasyOCR (MASK) → VevorMaskBatchUnion → GrowMask → FeatherMask → ImageCompositeMasked

Union first, then grow and feather. If you feather each region individually and union afterwards you get overlapping halos where boxes are close together, and the soft edges double up. One union, one grow, one feather, one edge.

Where people get burned

An empty mask batch sails downstream. OCR finds no text in a flat product shot, the mask batch has zero frames, this node passes it through unchanged, and whatever consumes it next either errors with a shape complaint or silently does nothing. If a workflow is occasionally a no-op, log the mask's shape before you blame the sampler.

Boxes, not outlines. Every region mask coming down this pipe is a filled rectangle - the OCR nodes derive them from quad corner extremes, so rotated or slanted text gets a fat axis-aligned box around it. Unioning twenty of those can cover a lot more picture than the text does. That's usually fine when you're erasing before a redraw and noticeably not fine when you're inpainting with a tight prompt.

Overlap is union, not averaging. Two adjacent label boxes sharing a sliver of padding become one continuous white block. If you needed them separate, you wanted the batch, not the union.

It's an unglamorous node that fixes a specific silent failure. Which, honestly, is the highest compliment you can pay a plumbing node - you install it once, it never appears in a screenshot, and one whole class of "my mask doesn't work" thread stops applying to you.

Categoryvevor/mask

Inputs (1)

NameTypeDefaultDescription
maskMASK—

Outputs (1)

NameTypeDescription
maskMASK—