Nodes/ComfyUI 1hewNodes/Multi Mask Math Ops
ComfyUI Node

Multi Mask Math Ops

Union, subtract, XOR — boolean math for your masks

By 1hew·Created about a year ago·Updated 8 days ago· 33
Multi Mask Math Ops
  • mask_1
  • mask_2
  • mask
operationor

Mask selection is usually wrong on the first pass. Your face mask covers the chin, your background mask swallows half the subject, and what you actually need is both of these minus that bit there. That's the whole job of Multi Mask Math Ops (1hew_MaskMathOps) - boolean operations on masks: union, intersection, difference, XOR.

It's in the 1hewNodes/multi group of the 1hewNodes pack, sitting alongside the pack's other mask utilities. The display name says "Multi" and the engine is built to chain masks, though the schema you'll see in the UI exposes two of them: mask_1 and mask_2.

How it works

The math is what you'd hope for and nothing more:

  • or - union, max of the masks. Combine a face mask and a hands mask into "everything I care about."
  • and - intersection, min. The overlap between two selections.
  • subtract (a-b) - clip mask_1 minus mask_2, so you can carve a hole in one selection using another.
  • subtract (b-a) - same, reversed.
  • xor - absolute difference. Symmetric difference: the parts where they don't agree.

Masks are resized to match the first input (LANCZOS), so slightly different sizes don't error out - a common complaint with stricter mask nodes. It also batch-broadcasts: if one mask has 4 frames and the other has 1, the single one is cycled across the batch.

Inputs and outputs

  • mask_1 - required, the base mask.
  • mask_2 - optional. Leave it disconnected and you get mask_1 back (via the identity-ish path), so it doesn't fall over in a half-wired graph.
  • operation - the combo selector, default or.
  • mask - the output.

Installing it

Part of the 1hewNodes pack:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

or search "1hewNodes" in ComfyUI Manager, then restart. Nothing to download.

Where it actually earns its keep

The killer use case is inpainting. Build an "everything to regenerate" mask with or, then use subtract (a-b) to remove the bits you don't want touched - say, a face you want preserved. That's a workflow you'll build once and reuse constantly. It also shines for compositing: XOR is great for finding where two selections disagree, which is exactly what you want when comparing a model's segmentation against your manual mask.

One honest note: the "Multi" in the name is aspirational on the surface - the visible schema gives you two masks, though the underlying code will also sweep up extra mask_N inputs if the graph hands them over. If you genuinely need to combine four masks, the pack's Multi Mask Batch can merge them into a batch first, then this node's operations apply across the batch. For the 95% case of "combine two, subtract one," this is the one you'll reach for.

Category1hewNodes/multi

Inputs (3)

NameTypeDefaultDescription
mask_1MASK
operationCOMBOor5 options: or, and, subtract (a-b), subtract (b-a), xor
mask_2optMASK

Outputs (1)

NameTypeDescription
maskMASK