🍒Mask_Add_Switch🔄蒙版合并开关
Merge two masks — and mind which way up yours are drawn
- masks_a
- masks_b
- MASKS
Mask_Add_Switch combines two masks into one, with a single toggle that handles the two competing mask conventions ComfyUI workflows run into. If you've ever built a compositing or inpainting graph and realized one mask is "white background with black cutouts" and another is "black background with white cutouts," you know the pain this exists to kill. The name says "add," but the actual math is a min merge - and understanding that is the difference between this node working and silently doing the wrong thing.
How it works
Both masks are reduced to 2D, then merged with torch.min(a, b). Here's the subtle part: min keeps a pixel white only where both masks are white. On the white-background / black-element convention (black = the thing you cut out, white = empty canvas), that behaves like a union of the black regions - exactly what you want when you're combining two cutouts into one mask. Flip the convention to white-foreground / black-background, and min becomes an intersection instead, keeping only the overlap. Same operation, opposite result, purely because of which side means "the thing."
The invert_switch doesn't change the merge - it changes the output format. With invert_switch on, you get the merged mask in white-background/black-element form (this pack's native convention, the same one Transparent_Area_Cropper expects). Off, you get it inverted as black-background/white-element. Pick the setting that matches what your downstream node expects.
The inputs that matter
- masks_a / masks_b - the two masks. Both MASK type.
- invert_switch - output convention: on = white background with black elements (this pack's native convention, the same one
Transparent_Area_Cropperexpects), off = black background with white elements.
One output: MASKS, a single merged MASK tensor clamped to 0–1.
Installation
Part of ComfyUI_KimNodes:
cd ComfyUI/custom_nodes
git clone https://github.com/wjl0313/ComfyUI_KimNodes
Restart ComfyUI. No extra dependencies.
Common issues
This is a "check your convention" node, so the failure mode is silent and visual. If both inputs are white-foreground masks (the ComfyUI default for most mask generators - white = selected region), min gives you the intersection, not the union, and the merged mask will look "thinner" than either input. The workaround is to invert your inputs first (or flip invert_switch and read the result carefully). Also worth noting: it only takes two masks. For three or more you'll chain two of these, which is fine but adds clutter. It's a small utility whose whole job is the toggle - get that toggle right and it's exactly the merge tool you wanted.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| masks_a | MASK | — | |
| masks_b | MASK | — | |
| invert_switch | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASKS | MASK | — |