Mask Combiner (RMBG) 🎭
Merge, intersect, or subtract up to four masks
- mask_1
- mask_2
- mask_3
- mask_4
- MASK
You've got two masks and you need one. Maybe one from a background remover and one from a YOLO face detector, and you want them merged. Or you want the overlap of two, or one with a chunk cut out of the other. Mask Combiner does the boolean algebra: union, intersection, difference, on up to four masks at once.
This is plumbing, and good plumbing is invisible. In any real segmentation workflow you end up with masks from different sources - a subject mask here, a hair-detail mask there, a region you manually painted - and combining them cleanly is the difference between one tidy node and a spaghetti of image-math nodes. Mask Combiner is that one tidy node.
How it works
It takes your masks and applies a set operation to them, pixel by pixel. Three operations, and they mean exactly what they say:
combine- union. Everything masked in any input ends up masked. This is the default and the one you'll use most: stack a body mask and a hair mask, get the whole subject.intersection- only the pixels masked in all inputs survive. Use it to constrain - "the part of the subject that's also inside this region."difference- subtract later masks from the first. Mask A minus mask B. Great for punching a hole: take a full-subject mask, subtract the face, and inpaint everything but the face.
The inputs and outputs that matter
mask_1(required) - your base mask.mask_2,mask_3,mask_4(optional) - up to three more to combine with it. Connect as many as you need; unconnected ones are ignored.mode-combine/intersection/difference, as above.
One output: MASK. Wire it wherever a mask goes next - an extractor, an inpaint conditioning node, another combiner if you're doing something baroque.
How to install it
- ComfyUI Manager: search
Comfyui-RMBG, install, restart. - Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/1038lab/ComfyUI-RMBG, thenpip install -r requirements.txt, and restart.
Pure math, no model - instant.
One thing to watch
difference is order-sensitive: it's mask_1 minus the rest, not a symmetric operation. If you're getting the inverse of what you expected, you've probably got your masks plugged into the wrong slots - swap mask_1 and mask_2. The other gotcha is size: masks of different dimensions don't combine meaningfully, so make sure everything upstream is working at the same resolution before it reaches here. If your masks come from different-sized sources, resize them to match first.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_1 | MASK | — | |
| mode | COMBO | combine | 3 options: combine, intersection, difference |
| mask_2opt | MASK | — | |
| mask_3opt | MASK | — | |
| mask_4opt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |