Nodes/ComfyUI_agilly1989_motorway/InvertMask_motorway_edition
ComfyUI Node

InvertMask_motorway_edition

Flip a mask white-for-black from inside the pipe

By agilly1989Β·Created 2 years agoΒ·Updated about a year agoΒ· 7
InvertMask_motorway_edition
  • MOTORWAY πŸšŒπŸ’¨
  • MOTORWAY πŸšŒπŸ’¨
β—„INPUT_mask_keymaskβ–Ί
β—„OUTPUT_MASK_keyMASKβ–Ί

InvertMask_motorway_edition is the simplest node in this pack, and it does exactly one thing: take a mask and flip it. White becomes black, black becomes white. The only difference from core ComfyUI's InvertMask is that the mask arrives via a Motorway key instead of a socket, and the inverted result goes back into the pipe.

Why you'd bother inverting a mask

More often than you'd think. Segmentation models and background-removal tools don't always agree with you about what's "foreground." A BiRefNet or SAM pass might hand you a mask where the subject is white and the background is black when what you actually want for your workflow is the inverse - say, to keep the background and erase the subject, or to feed the "outside" region into an inpainting pass. Inverting is also how you turn "remove the person" into "keep the person," depending on which convention your masker uses. The KB's background-removal essay is full of examples where the mask semantics don't match the use case; this is the one-node fix for the most common mismatch.

Because it's a single key in and a single key out, there's very little to configure:

  • INPUT_mask_key (default "mask") - which pipe key holds the mask to invert.
  • OUTPUT_MASK_key (default "MASK") - where the inverted mask is stored.

Note the defaults don't overwrite each other: if your downstream reads "mask", you'll want to either point the output at "mask" or update the downstream key, because by default the inverted mask lands under "MASK" (uppercase) while the original stays put. That's the kind of default-vs-intent mismatch that produces the pack's signature error.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/agilly1989/ComfyUI_agilly1989_motorway

Restart ComfyUI, or install via ComfyUI Manager. No pip deps, no model files - a mask flip is pure tensor math.

The caveats, briefly

Same pack-wide story as every _motorway_edition node: one-developer beta, README-warned breakage, and a current repo HEAD that comments the generated node registration out, so a fresh clone may not even list this node. If you hit 'MotorwayClass' object has no attribute 'hash_', a key you referenced was never written into the pipe - for this node that's almost always a typo in INPUT_mask_key or a masker node upstream that never ran. And honestly, this is the poster child for "do you need the pipe at all": if inverting a mask is the only motorway-ed thing in your graph, the stock InvertMask does the identical flip with one less abstraction layer. The wrapper exists for the workflow that's already routing everything through keys.

Categoryagilly1989 Nodes/Motorway-ed/mask

Inputs (3)

NameTypeDefaultDescription
MOTORWAY πŸšŒπŸ’¨MOTORWAY πŸšŒπŸ’¨β€”
INPUT_mask_keySTRINGmaskβ€”
OUTPUT_MASK_keySTRINGMASKβ€”

Outputs (1)

NameTypeDescription
MOTORWAY πŸšŒπŸ’¨MOTORWAY πŸšŒπŸ’¨β€”