Threshold Mask
Turn a wishy-washy mask into a crisp yes-or-no
- mask
- MASK
Threshold Mask takes any mask and snaps every pixel to either 1.0 or 0.0 depending on whether it's above a value you set. It's the "stop being wishy-washy" node: a soft gradient, a noisy alpha, a feathered edge - all become a hard, binary decision. It's the mask equivalent of a binarize/level adjustment, and it's what you reach for when a soft mask is causing soft problems.
Why you'll reach for it
Masks accumulate fuzz. A SAM segmentation returns confident whites with a fringe of grey. A channel you extracted from a JPEG has noise all over it. A mask that went through too many resize-and-composite steps has lost its clean edges. Half the time that fuzz is harmless, but half the time it's exactly what's causing your problem - the grey fringe gets interpreted as "regenerate a little bit here," and a little-bit regeneration is how you get halos and ghosting.
Threshold Mask is the cleanup step. Set the cutoff at 0.5 (the default) and everything above becomes solid white, everything below becomes solid black. You get a clean, confident mask, and downstream nodes stop having to guess what you meant.
It's also a gatekeeper. In multi-stage pipelines, thresholding a mask is how you force a hard decision before a boolean operation, a composite, or a detector handoff - and since MaskComposite's and/or/xor modes round internally anyway, thresholding first makes the outcome predictable.
How it works
The mechanism is one comparison: (mask > value), cast to float. Every pixel strictly greater than the threshold becomes 1.0; everything else, including pixels exactly equal to the threshold, becomes 0.0. It's elementwise, instant, and runs on the GPU. Note the strict inequality - a pixel sitting exactly on the threshold goes black, which is a corner case worth knowing if you ever wonder why your 0.5 value thresholded at exactly 0.5 gave you holes.
The inputs and outputs
mask- the input.value- the cutoff, 0.0 to 1.0, default 0.5. Step 0.01, so you can tune it precisely to catch or drop a specific grey level.
One output, MASK.
Getting it
Core ComfyUI, nothing to install. It's in comfy_extras/nodes_mask.py, part of the same family as the other mask utilities.
Where people get burned
- It's a hard step, and that's the point. Thresholding destroys soft edges. If you threshold a feathered mask and then feed the result straight to a sampler, you've reintroduced the hard seam you were trying to remove. The standard chain is threshold then feather - harden the decision, then soften the edge.
- The strict
>trips people. Pixel values exactly at the threshold don't survive. If you're thresholding a mask full of exactly-0.5 greys, nudgevalueto 0.49. - Don't threshold before you know the polarity. If the "right" answer is inverted, you've got a binary mask full of wrong answers and no softness left to hide it. Invert first, then threshold, then feather - that ordering saves a regeneration.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| value | FLOAT | 0.500–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |