Mask Composite YC
Stamp one mask onto another at any position — with multiply, XOR, overlay, and friends
- destination
- source
- mask
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), andnatural_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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| destination | MASK | — | |
| source | MASK | — | |
| x | INT | 00–8192 | — |
| y | INT | 00–8192 | — |
| operation | COMBO | 8 options: multiply, add, subtract, and, or, xor, +2 | |
| opacity | FLOAT | 1.000–1 | — |
| blend_power | FLOAT | 0.500–1 | 调整自然混合的强度,值越高越接近简单相加 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |