Nodes/ComfyUI/Combine Masks
ComfyUI Node Runs on cloud

Combine Masks

Your mask-building workbench, with an offset

By Comfy-Org·Created 4 years ago·Updated about 16 hours ago· 130,493
Combine Masks
  • destination
  • source
  • MASK
x0
y0
operation

Combine Masks is where masks get built rather than drawn. It pastes one mask onto another at an offset, with six operations to choose from - multiply, add, subtract, and, or, xor. If you've ever needed the union of two selections, or a face mask carved out of a hair mask, or a small region placed onto a big canvas, this is the node. It's the mask-world equivalent of ImageCompositeMasked, and it's the piece that turns separate detection masks into one coherent inpaint mask.

Why you'll reach for it

Most mask workflows start with several region masks - a face mask, a hair mask, a background mask, each from its own detector or paint. Almost no workflow wants those as separate masks. You want one mask that says "regenerate all of this." Combine Masks is the glue.

The operation dropdown is the whole personality:

  • multiply - intersection. Both masks must be active. Use it when a pixel belongs only if both regions say so.
  • add - union, but it can exceed 1.0 and gets clamped. The casual way to merge regions.
  • subtract - carve one region out of another. The classic: take the full body mask, subtract the face mask, and you get "everything but the face."
  • and / or / xor - boolean logic on rounded values. These operate on masks as if they were binary (any value above roughly 0.5 counts as true), which gives you clean set operations without worrying about partial overlap adding up.

And then there's x and y, which is what makes it more than a combine tool. You place source onto destination at an offset - which is how you take a small face-region mask and stamp it at the right position on a full-frame canvas. Pair it with SolidMask as the blank destination and you've got a paste tool.

How it works

The destination is the canvas; the source is what gets placed onto it. The source's overlapping region is combined with the destination's at that location using the chosen operation, and the final result is clamped to 0.0–1.0. Only the overlap region is affected - the rest of the destination passes through untouched. The boolean operations round before comparing, so they behave like thresholded sets; the arithmetic ones preserve soft values.

The inputs and outputs

  • destination - the base mask, the canvas.
  • source - the mask being placed onto it.
  • x, y - where the source lands on the destination (top-left).
  • operation - multiply, add, subtract, and, or, xor.

One output, MASK.

Getting it

Core ComfyUI, nothing to install. It's in comfy_extras/nodes_mask.py with the rest of the mask family.

Where people get burned

  • Order matters. destination and source are not symmetric for subtract or for placement. "subtract source from destination" is not the same as "subtract destination from source." If your result is inverted, you swapped them.
  • The boolean ops are hard. and/or/xor round to binary, so soft feathered masks lose their edges the moment they go through these. Use multiply if you want to keep gradients.
  • Offsets outside the canvas get clipped silently. The source just disappears past the destination's edge. If something's vanishing, check your x/y against the canvas size.
Categoryimage/mask

Inputs (5)

NameTypeDefaultDescription
destinationMASK
sourceMASK
xINT00–16384
yINT00–16384
operationCOMBO6 options: multiply, add, subtract, and, or, xor

Outputs (1)

NameTypeDescription
MASKMASK