Nodes/opencv-comfyui/OpenCV sqrBoxFilter_0
ComfyUI Node

OpenCV sqrBoxFilter_0

Squared pixels, boxed up — the local-variance building block

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV sqrBoxFilter_0
  • src
  • dst
  • nparray
ddepth
ksize
anchor
normalize
borderType

The name reads like OpenCV ran out of syllables, but sqrBoxFilter is one of the most useful primitives in this whole pack hiding behind a boring title. Instead of averaging the pixels in a window like a normal box blur, it averages the squares of the pixels in that window. That one change turns a blur into a local-statistics machine: window-averaged x² is the first half of variance, which means this node is how you build local standard deviation, texture/detail maps, and contrast-driven effects inside a ComfyUI graph.

Reach for it when you want to sharpen only where the image is already detailed, flatten only the flat areas, weight an effect by local contrast, or drive an enhancement pass with a per-pixel "how busy is this neighborhood" signal. There's no polished "Detail Enhancer" here - this pack ships raw cv2 functions and nothing hand-tuned - so sqrBoxFilter is the raw material you'd want for exactly those jobs.

How it works. For every output pixel, OpenCV sums src² over the ksize window. With normalize on, it divides by the window area and you get the mean of the squares; chain the output into sqrt_0 and you have root-mean-square. Subtract a regular boxFilter mean squared and take sqrt_0 again, and you've computed true local standard deviation. Leave normalize off and the raw sums overflow fast on 8-bit input, so keep it on unless you have a reason not to.

The inputs that matter:

  • ksize - a STRING, and you have to type the window as a Python literal like [3, 3]. This trips everyone up exactly once.
  • anchor - STRING; (-1, -1) centers the window on the pixel, which is what you want.
  • ddepth - output depth; -1 means "same as the source".
  • normalize - BOOLEAN; keep it true.
  • borderType - INT border enum (0 is constant border); default is fine for most jobs.

There's also an optional dst input. The author's own README says to avoid the optional out-parameters, and that's good advice - leave it disconnected.

Output is a single nparray. That's not a ComfyUI IMAGE, so you'll send it to Nparrays2Image to actually see it.

Install. ComfyUI Manager is the easy route - search the pack title "opencv-comfyui" and hit install. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart ComfyUI. Its requirements.txt pulls opencv-contrib-python, numpy, torch - you already have torch and numpy, and most installs already have OpenCV from some other node. If it's genuinely missing, pip install opencv-python-contrib. One known landmine: if you see Cannot import name 'guidedFilter' from 'cv2.ximgproc', you have conflicting OpenCV packages - make sure you don't have both opencv-python and opencv-contrib-python installed side by side.

Gotchas. This is an auto-generated pack and the author flags it up front: "Expect dragons!" The two that bite here are feeding in a raw ComfyUI IMAGE (wrong - convert with Image2Nparray first; it also only accepts batch_size 1, so on batches use ImageFromBatch(length=1)), and typo-ing the ksize literal, which throws invalid syntax (<unknown>, line 0). Fix the string, not the pack.

Also, sqrBoxFilter_1 is the identical twin of this node - same inputs, same output, same generated wrapper. Pick either and move on.

Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
srcNPARRAY
ddepthINT
ksizeSTRING
anchorSTRING
normalizeBOOLEAN
borderTypeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY