ComfyUI Node Runs on cloud

Masks Subtract

Cut one mask out of another in ComfyUI

By WASasquatch·Created 3 years ago·Updated about a year ago· 1,812
Masks Subtract

      Masks Subtract takes one mask away from another - the white area of the second mask gets removed from the first. It's the mask-math equivalent of "select this, but not that." If you've got a region masked and you want to carve a hole in it (exclude a face from a background mask, cut a subject out of a selection), this is the node.

      Mask arithmetic is bread-and-butter for anyone doing targeted inpainting or region-based effects. You rarely get the exact mask you want from a single source; you build it by combining simpler masks - adding them together, intersecting them, or, here, subtracting one from another.

      How it works

      Both masks are grayscale where white means "included" and black means "excluded." Subtraction removes the second mask's white region from the first: anywhere the second mask is white, the result goes black, regardless of what the first mask said there. Everywhere else, the first mask passes through. The output is a new mask that's the first one with a bite taken out of it.

      Concretely: mask A covers your whole subject, mask B covers just the hands. Subtract B from A and you get "the subject except the hands" - a mask you can use to apply an effect everywhere but the hands.

      The inputs and outputs that matter

      You wire in two masks - the one you're subtracting from and the one you're subtracting - and get a single mask out: the first minus the second. That result flows into whatever consumes a mask (inpaint, composite, selective filter). It pairs naturally with the rest of WAS's mask family - combine masks to build up a region, subtract to carve it back down.

      How to install it

      Ships in WAS Node Suite. Install once via ComfyUI Manager (search WAS Node Suite, install, restart) or manually:

      cd ComfyUI/custom_nodes
      git clone https://github.com/WASasquatch/was-node-suite-comfyui
      pip install -r was-node-suite-comfyui/requirements.txt
      

      then restart. On Windows portable, run the pip step with python_embeded\python.exe -s -m pip install -r ... (or install.bat) so requirements land in ComfyUI's Python. No models needed.

      Common issues & troubleshooting

      Nothing got subtracted. The two masks have to actually overlap. If the second mask's white area doesn't sit on top of the first mask's white area, there's nothing to remove and the output looks unchanged. Preview both masks to confirm they line up in the same coordinate space and size.

      Order matters - you subtracted the wrong way. Subtraction isn't symmetric: A minus B is not B minus A. If the result is the opposite of what you wanted, swap which mask goes into which input. Think "keep the first, remove the second."

      Ragged edges where the cut happens. Subtracting a hard-edged mask can leave a jagged boundary along the cut. If the seam matters, smooth the result afterward (Mask Smooth Region) or make sure the input masks were feathered before subtracting.

      Size mismatch errors. Mask operations expect both masks at the same resolution. If A and B were generated at different sizes, you'll get an error or a misaligned cut. Resize one to match before subtracting.

      The suite won't import. WAS Node Suite is large and unmaintained since late 2023; the recurring failure is an "Import Failed" after a ComfyUI update, from a dependency version clash (opencv the usual culprit). Reinstall the requirements against your ComfyUI Python and restart. The mask math is reliable - it's the suite install that occasionally breaks.

      Categoryx

      Inputs (0)

      No inputs

      Outputs (0)

      No outputs