Nodes/opencv-comfyui/OpenCV edgePreservingFilter_1
ComfyUI Node

OpenCV edgePreservingFilter_1

The edge-preserving filter, second overload — and the two knobs that matter

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV edgePreservingFilter_1
  • src
  • dst
  • nparray
flags
sigma_s
sigma_r

edgePreservingFilter_1 is the identical twin of edgePreservingFilter_0 - same function, second overload, no behavioral difference. OpenCV declares the filter once for MatLike and once for UMat, and this pack emitted a node for each. If that's the only thing you came here to learn, you're done; you can use either. If you came to figure out what the filter does and how to set it, read on - because this is one of the genuinely useful nodes in the pack.

What it is

It's OpenCV's edge-preserving smoothing: flat regions get averaged out, boundaries survive. Same family as a bilateral filter, faster to run, and controlled by two numbers that map cleanly onto intuition. sigma_s is the spatial scale - how big a neighborhood gets smoothed, so bigger values flatten over wider areas. sigma_r is the color-range scale - how different two colors must be to count as separate edges. Small sigma_r keeps detail; big sigma_r starts melting distinct colors together, which is where the flat, illustration-ish look comes from. flags picks the implementation: 1 (RECURS_FILTER) is the fast recursive one, 2 (NORMCONV_FILTER) is slower but higher quality.

A practical starting point for skin-smoothing: flags=1, sigma_s=50, sigma_r=0.15. For a cartoonier flatten, push sigma_r toward 0.4. Both are FLOATs you can wire to a slider, so it's easy to sweep them.

Inputs and output

src (NPARRAY), flags (INT), sigma_s (FLOAT), sigma_r (FLOAT), and an optional dst that's the function's out-parameter - leave it unplugged, that's the intended use. One nparray output.

Install and house rules

It's in opencv-comfyui (geroldmeisinger). ComfyUI Manager → search OpenCV, or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Restart. No model downloads - requirements.txt is opencv-contrib-python, numpy, torch.

The recurring rules: in through Image2Nparray, out through Nparrays2Image, batch_size==1 only (use ImageFromBatch at length 1 otherwise), and don't feed it a grayscale array unless you enjoy CV_8UC1 assertion errors. It wants an 8-bit color image.

Worth the effort? For a node that's free, instant, and does "smooth without destroying edges" correctly, absolutely. The _0 vs _1 choice is a coin flip; the sigma_s/sigma_r tuning is where the actual craft lives.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
sigma_sFLOAT
sigma_rFLOAT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY