Nodes/ComfyUI-WJNodes/Bilateral Filter
ComfyUI Node

Bilateral Filter

Smooth out banding without smearing your edges

By 807502278·Created 2 years ago·Updated 11 months ago· 20
Bilateral Filter
  • image
  • mask
  • IMAGE
  • MASK
diameter30
sigma_color75.00
sigma_space75.00

Bilateral filtering isn't a WJNodes invention - it's a decades-old computer-vision technique, and a well-respected one, because it does something a plain blur can't: it smooths flat areas while leaving edges alone. A normal Gaussian blur averages every nearby pixel regardless of how different they are, which is exactly why blurring blurs edges too. A bilateral filter only averages nearby pixels that are also similar in color - so a smooth gradient gets smoothed further, but a hard edge between two very different colors stays sharp because the pixels on either side of it don't get averaged together.

WJNodes' own description of this node is specific about what it's for: repairing the subtle layered distortion - banding - that shows up after you've rescaled an image or mask's color or brightness one time too many. If you've ever pushed a levels adjustment or a color curve too far and started seeing faint stair-step bands where there should be a smooth gradient, that's the exact problem this node targets. (Bilateral filtering shows up elsewhere in the Stable Diffusion world too - ControlNet's author, lllyasviel, used the same filter as one step in a small tool for scrubbing adversarial noise out of training images - but that's a different application of the same underlying math, not what this node claims to do.)

The inputs and outputs that matter

  • diameter (default 30, range 1–2048) - how large a neighborhood around each pixel gets considered. Bigger diameter, more smoothing, and meaningfully more compute - this is the setting most likely to make the node slow if you push it high on a large image.
  • sigma_color (default 75) - how different two pixels' colors can be and still count as "similar enough" to blend. Push this up and the filter starts smoothing across bigger color differences, which is how you lose the edge-preservation property if you're not careful.
  • sigma_space (default 75) - how far away a pixel can be spatially and still be considered, independent of diameter. The two work together to shape the effective neighborhood.
  • image / mask (both optional) - connect either or both; the node filters whichever you provide.

Two outputs: IMAGE and MASK - the filtered versions of whatever you fed in.

Installing it

Via ComfyUI Manager: search ComfyUI-WJNodes, install, restart. Or manually:

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

This one has a real dependency to watch for. Its own description states plainly that it requires the cv2 (OpenCV) module at runtime. Most ComfyUI installs already have OpenCV pulled in as a dependency of some other common node pack, so this often just works - but if it doesn't, you're missing OpenCV specifically, not something WJNodes ships itself. pip install opencv-python into your ComfyUI environment resolves it.

Common issues & troubleshooting

Node errors on run, or fails to load at all. Check your console for an OpenCV import error first - per the node's own documentation, cv2 is required, and unlike some other nodes in this pack that fall back gracefully when an optional dependency is missing, this one doesn't advertise a fallback path.

Effect is barely visible. Push sigma_color up a bit before touching diameter - a small neighborhood with a low color threshold will do almost nothing on subtle banding, since very few nearby pixels will count as "similar enough" to blend.

Image looks softened everywhere, not just on the banding. You've pushed sigma_color and/or sigma_space too high, past the point where the filter is still discriminating between genuinely different regions. Back both off and increase them one at a time until the banding smooths out without the real edges going soft.

CategoryWJNode/ImageEdit

Inputs (5)

NameTypeDefaultDescription
diameterINT301–2048
sigma_colorFLOAT75.000.01–256
sigma_spaceFLOAT75.000.01–1024
imageoptIMAGE
maskoptMASK

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK