Nodes/RyanOnTheInside/Flex Mask Binary βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜
ComfyUI Node

Flex Mask Binary βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜

Turn a soft mask into a hard black-and-white one, reactively

By ryanontheinsideΒ·Created 2 years agoΒ·Updated 5 months agoΒ· 852
Flex Mask Binary βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜
  • masks
  • opt_feature
  • MASK
β—„strength1.00β–Ί
β—„feature_threshold0.00β–Ί
β—„feature_paramβ–Ύβ–Ί
β—„feature_moderelativeβ–Ί
β—„invertfalseβ–Ί
β—„subtract_original0.00β–Ί
β—„grow_with_blur0.0β–Ί
β—„mask_strength1.00β–Ί
β—„threshold0.50β–Ί

A lot of masks you get out of segmentation models or hand-painted regions are soft - grayscale gradients, anti-aliased edges. Sometimes that's exactly what you want; sometimes you need a hard, crisp cutoff instead, no in-between gray. Flex Mask Binary is the simplest way to get that: everything above a threshold becomes fully white, everything below becomes fully black. It's one of the "Targets/Masks" nodes in RyanOnTheInside's Flex system, so on top of the plain thresholding it can also react to an external signal instead of using one fixed cutoff for the whole clip.

How it works

threshold sets the base cutoff (0–1) - any mask value above it becomes white, below becomes black. The reactive part comes through feature_param: set it to threshold and wire an opt_feature in, and the cutoff itself moves per-frame with your feature signal instead of staying fixed, gated by feature_threshold and shaped by feature_mode (relative nudges the value around your base setting; absolute scales it from zero to the ceiling). Layered on top is the same post-processing set found across the Flex mask family: invert flips black and white, subtract_original removes a portion of the source mask back out of the binarized result, grow_with_blur softens the now-hard edges afterward if you don't want them razor-sharp, and mask_strength is a final overall multiplier.

Inputs and outputs that matter

  • masks (required, MASK) - the source mask or sequence.
  • threshold (default 0.5, 0–1) - the binarization cutoff.
  • invert (default off) - flips the result.
  • opt_feature (optional, FEATURE) - connect to make the threshold move over time.
  • Output - a single MASK.

Installing it

Via ComfyUI Manager: search "RyanOnTheInside," install, restart. Manually:

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

then restart. No model downloads - this is straightforward pixel-value comparison.

Common issues & troubleshooting

Mask is entirely black or entirely white. If your source mask is genuinely soft (small range between its darkest and lightest pixel), a threshold near either extreme can push the whole thing to one color. Check your source mask's actual value range before assuming this node is broken.

Edges look jagged after binarizing. That's the point of thresholding - you traded a soft gradient for a hard line. If you need the mask usable for compositing without a stair-stepped edge, use grow_with_blur afterward to soften it back up a little without losing the binary character.

Reactive threshold doesn't seem to do anything. Confirm feature_param is actually set to threshold and not left on None - as with the rest of the Flex family, the feature input being wired doesn't do anything by itself until you point it at a parameter.

CategoryRyanOnTheInside/FlexFeatures/Targets/Masks

Inputs (11)

NameTypeDefaultDescription
strengthFLOAT1.000–1Overall strength of the feature modulation (0.0 to 1.0)
feature_thresholdFLOAT0.000–1Threshold for feature activation (0.0 to 1.0)
feature_paramCOMBOChoose which parameter to modulate: - threshold: Dynamically adjust the binarization threshold - None: No parameter modulation
feature_modeCOMBOrelativeHow to apply the feature modulation: - relative: Changes are centered around the original value - absolute: Changes scale directly from zero to the maximum
masksMASKInput mask or sequence of masks to be processed (MASK type)
invertBOOLEANfalseWhen enabled, inverts the mask output (black becomes white and vice versa)
subtract_originalFLOAT0.000–1Amount of the original mask to subtract from the result (0.0 to 1.0)
grow_with_blurFLOAT0.00–10Amount of Gaussian blur to apply for mask growth (0.0 to 10.0)
mask_strengthFLOAT1.000–1Overall strength of the mask effect (0.0 to 1.0)
thresholdFLOAT0.500–1Base threshold value for binarization (0.0 to 1.0)
opt_featureoptFEATUREOptional feature input for modulation Connect any feature node here to control the effect. Features can come from audio, motion, color, or other sources.

Outputs (1)

NameTypeDescription
MASKMASKβ€”