Nodes/opencv-comfyui/OpenCV pyrMeanShiftFiltering_1
ComfyUI Node

OpenCV pyrMeanShiftFiltering_1

The duplicate of the mean-shift flattening node — and why that's fine

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV pyrMeanShiftFiltering_1
  • src
  • dst
  • nparray
sp
sr
maxLevel
termcrit

Let's save you a minute of confusion: pyrMeanShiftFiltering_1 is a byte-for-byte duplicate of pyrMeanShiftFiltering_0. Same inputs, same output, same function call underneath. The _0/_1 numbering exists because OpenCV's Python stubs list two overloads of pyrMeanShiftFiltering and this pack auto-generates one node per overload - but the generator couldn't see any difference between them, so you get two identical nodes. If you're deciding which to drag in, flip a coin.

That's the whole "it's this node" story. For the why you'd use it at all: this is OpenCV's edge-preserving color-flattening filter. It replaces each pixel with the mean of nearby pixels that are similar in both space and color, so smooth gradients collapse into flat poster-like regions while hard edges survive. Good for a stylized watercolor look before an img2img pass, or for pre-segmenting an image into clean blobs.

What you set

The interesting inputs are sp (spatial search radius, in pixels) and sr (color radius - how far apart in color two pixels can be and still count as "same"). Both are plain floats. maxLevel is pyramid depth; 0 is fine, 1 cleans up flat areas nicely. termcrit is a Python-literal string, format (type, maxCount, epsilon) - type 3 means COUNT+EPS, so (3, 10, 1) = "stop after 10 iterations or once change drops below 1". dst is an optional OpenCV out-parameter; leave it unplugged.

The catches that will actually bite

  • termcrit is parsed with ast.literal_eval, so bad syntax = invalid syntax (<unknown>, line 0). Write it as a tuple.
  • The node operates on BGR nparray, not Comfy IMAGE. It goes IMAGEImage2Nparray → this node → Nparrays2ImageIMAGE. Yes, it's clunky. It's the price of this pack exposing raw OpenCV.
  • Only batch_size==1 is supported. A batched image throws Only images with batch_size==1 are supported! - fix it with an ImageFromBatch node at length=1.
  • Output comes back BGR, and Nparrays2Image assumes BGR for 3-channel arrays, so colors stay right as long as you use the pack's converter.

Install

Search "OpenCV" in ComfyUI Manager, or:

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

Restart ComfyUI and it's under image/OpenCV. No model files, no downloads - just OpenCV itself. If you see Cannot import name 'guidedFilter' from 'cv2.ximgproc' at load, that's a conflicting OpenCV install, a known headache with a known fix linked in the README.

So: use _0 or _1, doesn't matter. The author literally warns "expect dragons" - and the first dragon is that half the menu is duplicated overloads.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
spFLOAT
srFLOAT
maxLevelINT
termcritSTRING
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY