🐳遮罩运算
Boolean mask math that lines the masks up first
- 遮罩A
- 遮罩B
- 运算结果
- 对齐后遮罩A
- 对齐后遮罩B
- 运算信息
Mask boolean math - intersection, union, difference, XOR - is a standard toolkit in ComfyUI, but it has a dirty secret: it assumes both masks are already the same size and lined up. When your face mask comes from one detector and your hand mask from another, at different resolutions and offsets, plain boolean nodes give you garbage. 🐳遮罩运算 (Mask Align Boolean) fixes the alignment first, then does the math. That's the whole point, and it's genuinely the differentiator.
Concretely: you want the intersection of a face mask and a hair mask so you can inpaint just the hairline. Or the union of two body-part masks so you have one composite inpaint region. Or A − B to knock a face mask out of a background mask. When the source masks don't share a canvas, this is the node that makes those operations honest.
How it works
The node finds each mask's white region - the bounding box of where the mask actually is - and aligns the second mask to the first using your chosen 对齐方式 (alignment mode). There are nine: center, left, right, top, bottom, and the four corners. Alignment is based on the white area's bounds, so a small mask in the corner of a big canvas still lines up correctly with a mask that fills another canvas.
Then it applies the 布尔运算 (boolean operation) of your choice:
- 交集 (intersection), 并集 (union)
- 差集A-B (A minus B), 差集B-A (B minus A)
- 异或 (XOR), 非A (NOT A), 非B (NOT B)
Inputs and outputs
遮罩A(mask A) - the base mask (tooltip: 基准遮罩).遮罩B(mask B) - the mask to align (tooltip: 要对齐的遮罩).对齐方式- 9 alignment modes, default 居中 (center).布尔运算- 7 operations, default 交集 (intersection).- Optional
X轴偏移/Y轴偏移- nudge the aligned mask by extra pixels after alignment. Great for "slightly to the left" fixes. - Optional
阈值- the brightness threshold for what counts as "white region," default 0.5. If your masks are faint or anti-aliased, dropping this helps. - Optional
输出模式- 运算结果 (the result), 对齐预览 (alignment preview), or 详细输出 (detailed).
Outputs: 运算结果 (the boolean result, MASK), 对齐后遮罩A and 对齐后遮罩B (the aligned masks, handy for sanity-checking the alignment), and 运算信息 (STRING) describing what happened.
The 阈值 input is where people trip up. It's not a strength - it's the cutoff for deciding whether a pixel counts as "in the white region." Default 0.5 is right for clean masks. If your intersection comes out unexpectedly empty, your masks are probably misaligned or the threshold is too strict for soft-edged masks.
Install
Standard Pond Nodes install:
ComfyUI Manager → search "Pond Nodes" (comfy_Pond_Nodes)
or:
cd ComfyUI/custom_nodes
git clone https://github.com/Pondowner857/comfy_Pond_Nodes
cd comfy_Pond_Nodes
pip install -r requirements.txt
Restart after. It runs on torch and numpy (with scipy available for the harder mask math) - nothing extra to download. And the pack's standing warning: the README documents a console-spam conflict with comfyui_HiDream-Sampler.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| 遮罩A | MASK | 基准遮罩 | |
| 遮罩B | MASK | 要对齐的遮罩 | |
| 对齐方式 | COMBO | 居中对齐 | 以遮罩A的白色区域为基准对齐 |
| 布尔运算 | COMBO | 交集 | 布尔运算类型 |
| X轴偏移opt | INT | 0-2048–2048 | 额外的X轴偏移 |
| Y轴偏移opt | INT | 0-2048–2048 | 额外的Y轴偏移 |
| 阈值opt | FLOAT | 0.500–1 | 白色区域检测阈值 |
| 输出模式opt | COMBO | 运算结果 | 输出内容选择 |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| 运算结果 | MASK | — |
| 对齐后遮罩A | MASK | — |
| 对齐后遮罩B | MASK | — |
| 运算信息 | STRING | — |