遮罩混合丨模式
Eight blend modes to turn several masks into one region
- mask1
- mask2
- mask3
- mask4
- mask5
- mask
- image
- raw_mask
The whole masking game is combining regions: the face mask from a detector, the hand mask from another, the manual selection you painted - and you need them merged into one mask your inpaint or detailer can consume. That's MaskBlend. Eight blend modes, up to five input masks in expert mode, plus feathering, thresholding, strokes and gradients. It's the "combine masks properly" node from the QING pack, and for anyone doing real mask engineering it's the one that sticks.
It's from ComfyUI-QING (display name "遮罩混合丨模式"). Display names are bilingual; the blend modes themselves are English.
How it works
The essential inputs:
mask1- the base mask. It's also the reference size: every other mask is resized to matchmask1before blending, so mismatched resolutions can't silently break the result.blend_mode- the operation:add(union),subtract(mask1 minus mask2),intersect(overlap only),xor(symmetric difference),invert(flip mask1),max/min(element-wise extremes),screen(soft lighten).addandintersectcover 90% of real use.feather_radius- softens mask edges (gaussian blur) in pixels, 0–100. Raise it when the blended mask has harsh seams.threshold- 0–100, converts the blended result to a binary mask. Default 50.invert_mask- flip the output.
In expert mode (expert_mode = true) you unlock mask2 through mask5, plus the extras: stroke_width/stroke_position to draw a border around the mask region, and gradient_type/gradient_direction/gradient_intensity to add a linear, radial, angular or diamond gradient mask instead of a flat one.
Three outputs: mask (the final, thresholded result), image (a visualization of the mask as an image, so you can see what you made), and raw_mask (the pre-threshold result - the soft, feathered version before it got binarized). That trio is thoughtful: raw_mask is what you feed an inpaint if you want soft edges, mask if you want hard edges.
Where it fits
The workflow that made this node essential: multiple detectors, one region. Face detector gives one mask, hand detector another, you add them, feather the join, and the merged region feeds a single detail/inpaint pass - no duplicate passes, no overlapping paints. subtract is the other star: "take the full-body mask, subtract the face mask" to get everything except the face, or to carve a hole. And intersect is how you say "only where the face mask AND my manual selection agree."
The honest take
It's the most capable mask-combiner in the pack and one of the few places the pack goes genuinely deep (5 masks, gradients, strokes). That depth has a cost: in normal mode you're fine, but expert mode is a lot of knobs for a job that add + feather_radius usually solves. My advice: start in normal mode, use add, and only open expert mode when you actually need a fifth mask or a gradient. The raw_mask output is the sleeper feature - most tools only give you the hard mask.
Installing
Part of ComfyUI-QING. ComfyUI Manager: search "ComfyUI-QING". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py # or: pip install -r requirements.txt
Restart ComfyUI. Pure pip deps (Pillow, opencv-python, scipy, scikit-image, cairosvg), no models. China mirror: --mirror --auto. Python ≥ 3.9.
Gotchas
The size rule is the big one: everything resizes to mask1, so if mask1 is low-res and mask2 is high-res, the blend happens at low-res and you lose detail. Feed the highest-res mask as mask1. Big feather radii genuinely cost time (the node precomputes kernels, but a 100px feather on a 2K mask is real work). And note threshold is 0–100, not 0–1 - setting it to 50 means "a pixel counts as selected above 50% intensity." If you blend two masks and the result looks unexpectedly empty or solid, threshold is the first thing to suspect.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| mask1 | MASK | — | |
| blend_mode | COMBO | add | 8 options: add, subtract, intersect, xor, invert, max, +2 |
| feather_radius | INT | 00–100 | — |
| invert_mask | COMBO | false | 2 options: false, true |
| threshold | INT | 500–100 | — |
| expert_modeopt | COMBO | false | 2 options: false, true |
| mask2opt | MASK | — | |
| mask3opt | MASK | — | |
| mask4opt | MASK | — | |
| mask5opt | MASK | — | |
| stroke_widthopt | INT | 00–50 | — |
| stroke_positionopt | COMBO | center | 3 options: center, inside, outside |
| gradient_typeopt | COMBO | none | 5 options: none, linear, radial, angular, diamond |
| gradient_directionopt | COMBO | horizontal | 5 options: horizontal, vertical, diagonal, radial_in, radial_out |
| gradient_intensityopt | FLOAT | 1.00–2 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| image | IMAGE | — |
| raw_mask | MASK | — |