Nodes/ComfyUI-YCNodes/Mask Composite YC
ComfyUI Node

Mask Composite YC

Stamp one mask onto another at any position — with multiply, XOR, overlay, and friends

By yichengup·Created 2 years ago·Updated 4 months ago· 48
Mask Composite YC
  • destination
  • source
  • mask
x0
y0
operation
opacity1.00
blend_power0.50

Core ComfyUI's ImageCompositeMasked pastes one image onto another. Mask Composite YC is the same idea but the inputs are masks and you get eight ways to combine them, not just "overwrite." You place the source mask onto the destination mask at x/y, pick an operation, and out comes one combined mask the size of the destination.

When would you actually reach for it? Building a compound region: you have a small subject mask you want to plant into a full-canvas mask at a specific spot (say, after a detector returned a localized region). Or you need boolean logic between two regions - subtract the hair mask from the face mask, take the XOR of two segmentation results, multiply two soft masks to intersect them. That's the practical niche: mask math with positioning, which plain MaskComposite in core doesn't give you.

The operations

Eight of them, and they split into two camps:

  • Boolean / arithmetic: multiply (intersect), add (union-ish, can exceed 1), subtract (cut source out of destination), and, or, xor (operate on thresholded values).
  • Blending: overlay (a Photoshop-style overlay where values below 0.5 get multiplied by 2 and above get the inverse treatment - good for keeping mask ranges sane), and natural_blend (a screen-like blend that keeps bright areas from blowing out; blend_power, 0–1, controls how aggressively it brightens - higher values behave closer to plain addition, per the author's own tooltip).

opacity (0–1) scales the source before the operation, which gives you soft-edged control even on the hard boolean ops.

The inputs that matter

destination and source (both MASK), x and y (up to 8192, positioning the source's top-left), then operation, opacity, and blend_power. Output is a single mask. The result is clamped to 0–1, so you won't get values that break a conditioning node.

One shape rule: the source just needs to fit on the canvas - anything hanging off the edge gets clipped. The destination is whatever you want the output size to be, so make it the big one.

Install

Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:

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

Restart ComfyUI. Standard deps (torch, numpy, pillow, opencv-python, scipy), no models. Look for it under "YCNode/Mask".

Gotchas

and / or / xor round both inputs to boolean first, so soft/feathered masks become hard-edged in those modes - feather afterward, or use multiply/add/natural_blend if you want softness preserved. And add can push values above 1 before the final clamp, which is why it clamps rather than saturating - you'll sometimes see the result look "flatter" than the sum you expected at the edges. Both are behavior, not bugs. If you just want to merge two batches of masks, that's the sibling node Mask Batch Composite, which concatenates instead of composing.

CategoryYCNode/Mask

Inputs (7)

NameTypeDefaultDescription
destinationMASK
sourceMASK
xINT00–8192
yINT00–8192
operationCOMBO8 options: multiply, add, subtract, and, or, xor, +2
opacityFLOAT1.000–1
blend_powerFLOAT0.500–1调整自然混合的强度,值越高越接近简单相加

Outputs (1)

NameTypeDescription
maskMASK