Mask: Combine
Union, Subtract, Intersect — Mask Math in One Node
- mask_a
- mask_b
- mask
JHPixelProMaskCombine does boolean algebra on two masks - union, subtract, intersect, difference, xor, add, multiply. That's the boring-sounding node that makes real compositing possible, and you'll reach for it constantly once you have SAM masks lying around. Union the face mask with the hand mask so both get inpainted. Subtract the background mask from the subject mask. Intersect two segmentations to find where they agree. This node is how you compose those decisions.
Inputs:
mask_a,mask_b- two MASKs.operation- add, subtract, intersect, union, difference, xor, multiply.blend_mode-hardorsoft_feather. Hard does the operation and stops; soft_feather feathers the result usingfeather_sigma.opacity(default 1.0) - how strongly the result applies, 0.0–1.0.feather_sigma(default 0) - feather radius for soft_feather mode, 0..64.
Output: a single MASK.
How it works: plain tensor ops on the float masks - add clamps, union takes the max, intersect takes the min, subtract knocks one out of the other - with an optional feather pass on top. Nothing exotic under the hood. The value is that it's all in one node with a readable dropdown instead of a hand-built chain of math nodes that nobody can read a week later.
The pattern that pays off: combine a coarse subject mask with a fine detail mask using subtract to knock out regions, or union to grow a selection before you blur it. Soft-feather mode is the one for visible seams - set feather_sigma around 2–4 and the composite edge stops showing banding. It slots neatly between a segmenter and the pack's Sub-Pixel Mask Refiner or Edge Smoother.
Install is the shared pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/ComfyUI-JH-PixelPro.git
cd ComfyUI-JH-PixelPro
pip install -r requirements.txt
Restart and it's under ComfyUI-JH-PixelPro/mask, or use ComfyUI Manager → search "ComfyUI-JH-PixelPro".
Troubleshooting: mismatched mask sizes will bite you. Feed two masks at different resolutions and the math still runs, but the result is subtly wrong - upscale one to match first. And know your add: it's a clamp, not a true sum, so 0.8 + 0.8 = 1.0. Don't use add to "brighten" a soft mask; that's what multiply or a normal blend is for. The pack README is explicit that this node is designed to sit after SAM/YOLO/rembg and before downstream compositing or inpaint - keep it in that spot.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_a | MASK | — | |
| mask_b | MASK | — | |
| operation | COMBO | union | 7 options: add, subtract, intersect, union, difference, xor, +1 |
| blend_mode | COMBO | hard | 2 options: hard, soft_feather |
| opacity | FLOAT | 1.000–1 | — |
| feather_sigma | FLOAT | 0.00–64 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |