Nodes/SaltAI-Open-Resources/Threshold Mask Regions
ComfyUI Node

Threshold Mask Regions

Turn a soft, noisy mask into something clean

By get-salt-AI·Created 2 years ago·Updated 2 years ago· 84
Threshold Mask Regions
  • masks
  • MASKS
black_threshold75
white_threshold175

Auto-generated masks - CLIPSeg output especially - often come back grayscale and a little noisy rather than a clean shape. SaltMaskThresholdRegion is the cleanup step: it clips a soft mask into something closer to binary, using two thresholds instead of one so you get a bit more control than a plain cutoff would give you.

What it does

Two parameters: black_threshold (integer, default 75, range 0–255) and white_threshold (default 175, range 0–255). Anything at or below black_threshold gets pushed to fully excluded (0); anything at or above white_threshold gets pushed to fully included. What's between the two thresholds is the dead zone - rather than a single hard cutoff turning your whole mask into a binary yes/no at one exact value, the gap between black and white thresholds gives you a controllable band, so a mask with a lot of mid-gray ambiguity doesn't all snap to one side or the other at an arbitrary single point. The output, MASKS, is the thresholded result.

Where you'd use it

Anywhere a downstream step needs a cleaner, more decisive mask than what you're currently holding - before a hard crop, before an inpaint where you want a precise boundary rather than a soft one, or as cleanup right after a CLIPSeg or edge-detection pass that came back rougher than ideal. It's also a natural step to run before SaltMaskErodeRegion, since erosion behaves more predictably on a cleaner, more binary mask than on one still full of soft gray values.

Installing it

ComfyUI Manager: search SaltAI-Open-Resources. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/get-salt-AI/SaltAI

Restart ComfyUI. No dependencies beyond the pack itself.

Common issues

Set the two thresholds too close together and you get aggressive, nearly-single-value binarization - fine if that's what you want, but it can leave mask edges looking jagged or stair-stepped rather than smooth, since there's almost no gradient band left to soften the transition. Set them too far apart and you barely change anything - the mask stays mostly soft and grayscale, which defeats the point if you were trying to clean up noise. There's no universally right pair of values; it depends on how noisy your source mask is and how hard an edge you actually want. If you thresholded a mask down to something cleaner but now the edge reads too harsh for a natural-looking composite, that's exactly the situation SaltMaskSmoothRegion is for - threshold first to clean up noise, then smooth lightly afterward if you want the edge softened back down without reintroducing the original mask's mid-gray ambiguity.

CategorySALT/Masking/Filter

Inputs (3)

NameTypeDefaultDescription
masksMASK
black_thresholdINT750–255
white_thresholdINT1750–255

Outputs (1)

NameTypeDescription
MASKSMASK