Flex Mask Binary β‘π ‘π π £π
Turn a soft mask into a hard black-and-white one, reactively
- masks
- opt_feature
- MASK
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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| strength | FLOAT | 1.000β1 | Overall strength of the feature modulation (0.0 to 1.0) |
| feature_threshold | FLOAT | 0.000β1 | Threshold for feature activation (0.0 to 1.0) |
| feature_param | COMBO | Choose which parameter to modulate: - threshold: Dynamically adjust the binarization threshold - None: No parameter modulation | |
| feature_mode | COMBO | relative | How to apply the feature modulation: - relative: Changes are centered around the original value - absolute: Changes scale directly from zero to the maximum |
| masks | MASK | Input mask or sequence of masks to be processed (MASK type) | |
| invert | BOOLEAN | false | When enabled, inverts the mask output (black becomes white and vice versa) |
| subtract_original | FLOAT | 0.000β1 | Amount of the original mask to subtract from the result (0.0 to 1.0) |
| grow_with_blur | FLOAT | 0.00β10 | Amount of Gaussian blur to apply for mask growth (0.0 to 10.0) |
| mask_strength | FLOAT | 1.000β1 | Overall strength of the mask effect (0.0 to 1.0) |
| threshold | FLOAT | 0.500β1 | Base threshold value for binarization (0.0 to 1.0) |
| opt_featureopt | FEATURE | Optional 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)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | β |