Nodes/ComfyUI_agilly1989_motorway/ThresholdMask_motorway_edition
ComfyUI Node

ThresholdMask_motorway_edition

Turn a soft mask into a hard cut

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

Mask math in ComfyUI is full of gradients - blur a mask and suddenly your "select the person" mask has a soft gray edge that decides mid-values. ThresholdMask is the node that puts its foot down: anything at or above your threshold becomes full white, anything below becomes full black. No in-between. This is the Motorway edition, so the mask comes out of the pipe by key and the binarized result goes back in.

When do you actually want that? Whenever a downstream step needs a definite yes/no rather than a "mostly." Inpainting regions where a soft edge would mean "regenerate half of this pixel," masking operations that composite onto a background, or cleaning up a depth or alpha map before it gets fed to a ControlNet preprocessor. It's a blunt instrument - you're throwing away all the gray information - but that's exactly the point. Used after a blur, ThresholdMask is how you get a clean hard-edged mask from something messy.

What to set

  • INPUT_mask_key (default mask) - the Motorway key holding the MASK you want to binarize.
  • value (default 0.5, 0–1) - the cut point. Pixels at or above this become 1 (white), below become 0 (black). Move it up to keep only the strongest parts of the mask.
  • OUTPUT_MASK_key (default MASK) - where the thresholded mask is written.

Output is the MOTORWAY with the hard-edged MASK stored under the output key.

Installing it

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

Restart; it's under agilly1989 Nodes β†’ Motorway-ed β†’ mask. ComfyUI Manager has the pack. No pip dependencies.

Where people get burned

The value threshold interacts with everything upstream. Blur a mask, then threshold at 0.5, and you've silently shrunk the region because the blur spread the intensity. If your inpainted area comes out smaller than your original selection, the threshold isn't wrong - it's doing its job, and you need to re-blur with a lower threshold or adjust.

And the Motorway standard: keys are case-sensitive and exact; 'MotorwayClass' object has no attribute 'hash_' means the key in INPUT_mask_key isn't in the pipe - check the spelling on the node that wrote mask. Finally, the pack is beta and the auto-cloned motorway-ed nodes have been enabled and disabled across releases. If an update makes the node vanish from the menu, that's the pack changing, not a broken install.

Categoryagilly1989 Nodes/Motorway-ed/mask

Inputs (4)

NameTypeDefaultDescription
MOTORWAY πŸšŒπŸ’¨MOTORWAY πŸšŒπŸ’¨β€”
INPUT_mask_keySTRINGmaskβ€”
valueFLOAT0.500–1β€”
OUTPUT_MASK_keySTRINGMASKβ€”

Outputs (1)

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