Nodes/SDVN Segment Anything/🧩 Invert Mask
ComfyUI Node

🧩 Invert Mask

Flip a mask with one node, and know it's a one-liner

By StableDiffusionVNΒ·Created 7 months agoΒ·Updated 7 months agoΒ· 1
🧩 Invert Mask
  • mask
  • MASK

SDVN InvertMask takes a MASK in and gives a MASK back, flipped: every white pixel goes black and every black pixel goes white. That's the whole node. The entire implementation is out = 1.0 - mask. It's a utility you'll grab constantly once you realize half the time you have the wrong mask for the job.

When you need the opposite mask

The classic case is inpainting. You segment a person out of a photo and end up with a mask covering the person - but the thing you actually want to regenerate is the background behind them, or the background is what you want to keep untouched. Feed the subject mask into InvertMask and suddenly the inpaint region is everything except the person. Same trick works for alpha compositing: if you want transparent = subject rather than transparent = background, this node flips the polarity.

It's also used inside the pack itself - SDVN SegmentAnything builds its alpha preview by inverting the segmentation mask and joining it as an alpha channel. So you're using the same flip the flagship node relies on.

The honest take

This is a two-line utility, and ComfyUI's core already ships an InvertMask node that does the identical thing. If you're reading this article you almost certainly installed it as part of the SDVN Segment Anything pack, and in that case it's handy to have on the same palette - and it keeps your workflow's nodes visually grouped. If you're only here for the invert, you could equally use the core node and save yourself the pack. No shame either way; the math is identical.

Using it

One mask input, one MASK output, nothing to configure, no downloads, no VRAM, no dependencies. Wire the mask in, wire the result into VAEEncodeForInpaint, ImageCompositeMasked, or a save node. It runs on every batch element and keeps your mask's resolution and shape intact.

One thing to keep in mind: masks in ComfyUI are single-channel float tensors in [0, 1], so 1.0 - mask is exact - no rounding, no dithering. If your mask has soft or feathered edges, inverting it keeps them soft rather than snapping them to hard black/white, which is usually what you want for clean inpainting seams (the inpainting KB doc's whole point about mask blur). If you ever need a hard-edged version, run a threshold before or after instead.

Install

It's part of the SDVN pack, so you get it with the rest:

cd ComfyUI/custom_nodes
git clone https://github.com/StableDiffusionVN/SDVN_Segment_Anything
pip install -r requirements.txt

or one click via ComfyUI Manager ("SDVN Segment Anything"), then restart. Unlike the segment nodes, this one never triggers a model download - it's ready the moment the pack loads. Boring, instant, and quietly essential.

CategoryπŸ“‚ SDVN/🎭 Mask

Inputs (1)

NameTypeDefaultDescription
maskMASKβ€”

Outputs (1)

NameTypeDescription
MASKMASKβ€”