Nodes/SaltAI-Open-Resources/Bilateral Filter Mask Regions
ComfyUI Node

Bilateral Filter Mask Regions

Smooth mask noise without blurring away the edge

By get-salt-AI·Created 2 years ago·Updated 2 years ago· 84
Bilateral Filter Mask Regions
  • masks
  • MASKS
diameter9
sigmaColor75.0
sigmaSpace75.0

A regular blur softens everything equally, including the exact boundary you're trying to keep sharp. Bilateral Filter Mask Regions doesn't have that problem - it only smooths pixels that are both spatially close and similar in value, so it cleans up noisy or jagged mask edges while leaving the actual silhouette boundary intact.

How it works

This is OpenCV's bilateralFilter, unchanged - the three parameters here (diameter, sigmaColor, sigmaSpace) are literally that function's arguments. It's the standard edge-preserving smoothing operation used across a lot of image processing, applied here to a mask instead of a color image.

Where it earns its place in this pack's filter family: a plain Gaussian blur is cheaper and simpler, but it has no concept of "this is an edge, protect it" - it treats a mask boundary the same as internal noise and softens both equally. Bilateral filtering is slower for exactly that reason (it has to evaluate both spatial distance and value similarity per pixel instead of just distance), but it's the right tool specifically when your mask has real noise you want gone and a real boundary you don't want touched.

The inputs and outputs that matter

  • masks (required, MASK).
  • diameter (optional, default 9, 1–31) - the pixel neighborhood it filters within. Bigger is a stronger, slower effect.
  • sigmaColor (optional, default 75, 0–200) - how different two mask values can be and still get blended together. Raise it to smooth across bigger value jumps, i.e. treat more of a gradient as "the same region."
  • sigmaSpace (optional, default 75, 0–200) - how far apart spatially two pixels can be and still influence each other.

Output is MASKS, a noise-reduced mask with the boundary preserved.

How to install it

ComfyUI Manager: search SaltAI-Open-Resources or SaltAI, install, restart. Manual:

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

then restart. OpenCV-backed - cv2 needs to be importable, which is near-universal in a working ComfyUI install already.

Common issues & troubleshooting

Edges start bleeding into background instead of just smoothing noise. That's sigmaColor set too high - cranking it up starts treating genuinely different values (mask vs. non-mask) as "the same," blending your masked region with unmasked background rather than just cleaning noise within it. Back it off.

Barely any visible change. Defaults (9 / 75 / 75) are a reasonable starting point, but if your mask was already clean - hard edges, little gradient - there's not much noise for this filter to remove. Try it on a rougher, speckled mask to see the effect clearly.

Mask shape is still wrong after filtering. This is a smoothing filter, not a shape-correction one. If your mask genuinely missed a limb or included background it shouldn't have, no amount of bilateral filtering fixes that - you need a better mask, not a cleaner one. Fix the source (better prompt to CLIPSeg, a corrected hand-drawn region) rather than trying to filter your way out of a wrong shape.

Feels slower than a blur node you've used before. It is - bilateral filtering is more expensive than a plain Gaussian blur because it's doing per-pixel comparisons on both position and value, not just position. On a large batch this is noticeable; it's the trade-off for keeping edges intact, not a sign anything's broken.

CategorySALT/Masking/Filter

Inputs (4)

NameTypeDefaultDescription
masksMASK
diameteroptINT91–31
sigmaColoroptFLOAT75.00–200
sigmaSpaceoptFLOAT75.00–200

Outputs (1)

NameTypeDescription
MASKSMASK