Nodes/comfyui-AGSoft/AGSoft Mask Composite
ComfyUI Node

AGSoft Mask Composite

Two masks, five ways to combine them — mask math without the headache

By Art-xmaster·Created 12 months ago·Updated a day ago· 23
AGSoft Mask Composite
  • mask1
  • mask2
  • mask_out
  • convert_mask_to_image
operationadd
devicecpu

Sometimes the mask you need doesn't exist yet - it's two masks that need to be unioned, subtracted, or intersected. Say you've got a face mask and a hair mask, and you want to inpaint only where they overlap, or everywhere except the eyes. AGSoft Mask Composite is the two-input mask operation node from the AGSoft pack: pick an operation, get a combined mask. It's the small piece that keeps mask pipelines from turning into five chained nodes.

How it works

Two masks in, one mask out, with a dropdown choosing the math. Underneath it's per-pixel operations on the mask tensors (the pack's mask utilities use OpenCV/NumPy under the hood, so it's fast even on cpu). The operation dropdown is the whole interface:

  • add - union. Brightness adds up; handy when you want the combined coverage of two masks.
  • subtract - mask1 minus mask2. Use it to carve out a region (e.g., remove the eyes from a face mask).
  • multiply - intersection. Only where both masks are white stays white.
  • max / min - element-wise brightest/darkest, which behave a lot like union and intersection but keep soft values rather than adding or zeroing them.

Like the other AGSoft mask nodes, it returns two outputs: mask_out (the real MASK) and convert_mask_to_image (the same thing rendered as a grayscale IMAGE for previewing).

The inputs that matter

  • mask1, mask2 - your two input masks. Order matters for subtract (and for add, since 1+1 clamps differently than 1+0), so keep track of which is which.
  • operation - the five options above. Default is add.
  • device - cpu/cuda, default cpu. A per-pixel combine is trivially cheap; you can ignore this unless you're doing thousands of them.

There's also a not-obvious gotcha worth knowing: masks don't auto-align. If mask1 and mask2 are different resolutions, the node operates on them as-is, and the output reflects that mismatch. Resize both masks to the same dimensions upstream (the pack ships Image & Mask Resize nodes for exactly this) if you're getting results that look "off."

Installing

Standard AGSoft install, nothing special:

cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft

Restart ComfyUI, or grab it through ComfyUI Manager ("comfyui-AGSoft"). No models to download. If the combined mask looks wrong, check resolution mismatch first, then check whether you actually want add vs max - they look identical on fully-white masks but diverge the moment either mask has soft or partial values.

CategoryAGSoft/Mask

Inputs (4)

NameTypeDefaultDescription
mask1MASK
mask2MASK
operationCOMBOaddОперация над двумя масками: add — объединение, subtract — вычитание, multiply — пересечение, max/min — выбор наибольшего/наименьшего значения.
deviceCOMBOcpuУстройство для вычислений. 'cuda' ускоряет обработку на GPU, но требует совместимой видеокарты.

Outputs (2)

NameTypeDescription
mask_outMASK
convert_mask_to_imageIMAGE