Nodes/comfy_Pond_Nodes/🐳遮罩运算
ComfyUI Node

🐳遮罩运算

Boolean mask math that lines the masks up first

By Pondowner857·Created about a year ago·Updated 21 days ago· 45
🐳遮罩运算
  • 遮罩A
  • 遮罩B
  • 运算结果
  • 对齐后遮罩A
  • 对齐后遮罩B
  • 运算信息
对齐方式居中对齐
布尔运算交集
X轴偏移0
Y轴偏移0
阈值0.50
输出模式运算结果

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.

Category🐳Pond/mask

Inputs (8)

NameTypeDefaultDescription
遮罩AMASK基准遮罩
遮罩BMASK要对齐的遮罩
对齐方式COMBO居中对齐以遮罩A的白色区域为基准对齐
布尔运算COMBO交集布尔运算类型
X轴偏移optINT0-2048–2048额外的X轴偏移
Y轴偏移optINT0-2048–2048额外的Y轴偏移
阈值optFLOAT0.500–1白色区域检测阈值
输出模式optCOMBO运算结果输出内容选择

Outputs (4)

NameTypeDescription
运算结果MASK
对齐后遮罩AMASK
对齐后遮罩BMASK
运算信息STRING