Combine Masks
The boolean math behind every clever masking trick
- image1
- image2
- IMAGE
Most masking problems that feel complicated are actually just set logic wearing a costume. "Mask the face but not the glasses," "mask everything except the background," "mask where these two regions overlap" - that's union, difference, and intersection, and Combine Masks is where Masquerade Nodes puts all of it in one place. If you've ever chained three or four mask nodes trying to hand-carve a weird shape, this is very likely the node that replaces all of them.
It takes two masks (or two images - more on that below) and an operation, and does pixel-wise math between them. union (max) takes the brighter pixel at every location, which is the standard "combine these two areas" move. intersection (min) takes the darker pixel, keeping only where both masks agree something's there. difference gives you what's white in the first mask but black in the second - the classic "this region minus that region" subtraction. multiply and add are the raw arithmetic operations (multiply behaves like intersection on already-thresholded masks; add behaves like union if you clamp the result). greater_or_equal and greater are pixel-value comparisons - greater collapses to the same result as difference on thresholded masks. multiply_alpha is the odd one out: it adds an alpha channel to the first image if it doesn't have one, then multiplies the second image (used as a mask) into that alpha - this is how you punch a mask-shaped hole of transparency into an image rather than into a separate mask.
The inputs that matter
- image1, image2 - the two masks (or images) to combine.
- op - the eight operations above.
- clamp_result - clamps output to 0–1. You want this on for almost everything; leave it off only when you're deliberately doing raw math and plan to clamp or round later yourself.
- round_result - snaps every pixel to a hard 0 or 1. Turn this on when you need a clean binary mask for something downstream that doesn't handle soft edges well; leave it off if you want to preserve feathering.
Output is a single resultant mask or image, wired straight back into whatever needs the combined result.
The one thing worth knowing that isn't obvious from the node itself: this works on full RGB/RGBA images too, not just single-channel masks. That's what makes multiply_alpha useful in practice - multiply a mask into an image's alpha channel and you've cut a transparent hole exactly where the mask said to, in one node, no separate "apply mask as alpha" step.
Installing it
Combine Masks comes bundled with the rest of Masquerade Nodes from BadCafeCode. Install via ComfyUI Manager (search "Masquerade Nodes") or manually with cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart. It's a pure math node - no models, no extra Python packages, nothing to download. The README itself is upfront that this pack was built to be dependency-free before ComfyUI Manager existed to handle dependencies for you, and points people toward Impact Pack if they don't specifically need that property; Combine Masks is exactly the kind of utility node where that trade-off doesn't matter much either way.
Common issues
The most common confusion isn't a bug, it's picking the wrong operation for the mental model you have. If you expected "subtract mask B from mask A" and got something that looks like an overlap instead, you probably reached for intersection when you wanted difference - intersection keeps where both are white, difference keeps where the first is white and the second isn't. If your result looks washed out or grey instead of crisp, that's usually add or multiply without round_result on - turn rounding on if you need a hard binary mask rather than a blended one. And if you're feeding in two masks of different sizes, resize them to match first; this node does pixel-wise math and doesn't resample for you.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image1 | IMAGE | — | |
| image2 | IMAGE | — | |
| op | COMBO | 8 options: union (max), intersection (min), difference, multiply, multiply_alpha, add, +2 | |
| clamp_result | COMBO | 2 options: yes, no | |
| round_result | COMBO | 2 options: no, yes |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |