Nodes/Comfyui-ergouzi-Nodes/2🐕Mask can be cut arbitrarily
ComfyUI Node

2🐕Mask can be cut arbitrarily

Boolean algebra for two masks at once

By 11dogzi·Created 2 years ago·Updated 2 years ago· 102
2🐕Mask can be cut arbitrarily
  • target_image
  • target_mask
  • source_image
  • source_mask
  • result_mask
  • result_image
operation

Sooner or later you end up with two masks and need to do actual math on them - combine two selections into one, cut one shape out of another, or keep only where they overlap. ComfyUI's core node set doesn't give you a single node for that; you end up chaining subtract/multiply-style workarounds. This node is the ergouzi pack's answer: pick an operation, feed it two masks (or two images), get the combined result back.

How it works

operation is the whole interface - a four-way switch that decides what happens between your source and target inputs:

  • merge - union. Anything masked in either input stays masked in the output.
  • crop - cuts one region out of the other, rather than combining them.
  • intersect - keeps only the area where both inputs overlap.
  • not_intersect - the inverse of intersect: everything except the overlap.

Everything else on this node is optional, and that's deliberate: you can drive it purely off masks (source_mask / target_mask), purely off images if you'd rather work at the pixel level, or feed both and let the node carry image data through the same boolean operation as the mask.

The inputs and outputs that matter

  • operation (enum, required) - merge / crop / intersect / not_intersect.
  • source_mask, target_mask (MASK, optional) - the two masks you're combining.
  • source_image, target_image (IMAGE, optional) - the equivalent, if you're operating on images rather than masks.

Two outputs: result_mask (MASK) and result_image (IMAGE) - whichever one matters depends on what you fed in.

How to install it

Search Comfyui-ergouzi-Nodes in ComfyUI Manager, or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/11dogzi/Comfyui-ergouzi-Nodes.git

Restart ComfyUI. Same standing note as the rest of this pack: this English repo is marked frozen in the README, with active development continuing on a Chinese-named sibling instead.

Common issues & troubleshooting

Result mask comes back empty or comes back full. That's usually correct, not broken. intersect on two masks that don't touch at all legitimately produces nothing; not_intersect on the same pair produces everything except a non-existent overlap, which is effectively both inputs unchanged. Check whether your two masks actually overlap before assuming the node is misbehaving.

crop looks inverted. Source and target aren't symmetric for this operation - which one is being cut from and which is doing the cutting depends on which input you plugged where. If the result looks backwards, swap source_mask/source_image with the target equivalents and try again.

Feeding it images instead of masks and expecting mask-only behavior. The image inputs exist so you can carry pixel data through the same operation, not as a shortcut to auto-generate a mask from an image. If you only care about the mask output, you don't need to touch source_image/target_image at all - leave them empty and work purely in result_mask.

Category2🐕/⛱️Mask

Inputs (5)

NameTypeDefaultDescription
operationCOMBO4 options: merge, crop, intersect, not_intersect
target_imageoptIMAGE
target_maskoptMASK
source_imageoptIMAGE
source_maskoptMASK

Outputs (2)

NameTypeDescription
result_maskMASK
result_imageIMAGE