OpenCV medianBlur_1
Smoothing without the halo
- src
- dst
- nparray
Spoiler up front, because it'll save you the confusion: medianBlur_1 and medianBlur_0 are the same node. opencv-comfyui generates a node per cv2 overload, cv2.medianBlur exists for both MatLike and UMat types, and you got two identical entries. The _1 is not an upgrade. Use whichever.
What it does is worth understanding, because it's genuinely different from the blur you probably default to. Instead of averaging a neighborhood (which is what Gaussian and box blurs do), a median filter takes the middle value of the neighborhood and uses that. The practical consequences: it shrugs off outliers - a few bright or dark specks literally vanish rather than smearing into the result - and it doesn't spread edges. No soft halos around sharp boundaries. You get denoising that leaves structure alone.
That's exactly what you want when you're prepping masks or edge maps in a diffusion workflow. Rough binary mask with salt-and-pepper specks from a threshold? medianBlur_1 cleans it without dissolving the boundary, so your inpaint region stays tight. Noisy depth or lineart before a ControlNet preprocessor? Same story. This is a microsecond-deterministic fix, and it beats both "re-run the segmenter" and "Gaussian it and hope."
Inputs and outputs
- src - one
NPARRAY(BGR uint8 by default). - ksize - the one knob, an
INT. Must be odd and positive: 3, 5, 7. Even values are an assertion failure, not a gentle suggestion. - dst - optional, skip it (out-parameter).
- nparray - the blurred result.
Setup
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or ComfyUI Manager → "opencv-comfyui" → install → restart. Dependencies: opencv-contrib-python, numpy, torch. Standard path: Image2Nparray → medianBlur_1 → Nparrays2Image, and remember Image2Nparray accepts batch_size==1 only.
Failure modes worth knowing: even ksize (assertion error), and OpenCV conflicts between custom nodes (Cannot import name 'guidedFilter' from 'cv2.ximgproc' - README links a fix). And the classic over-correction: this blur's only control is window size, so don't chase noise with a giant window and turn your mask into a melted silhouette. ksize=5 handles most jobs; drop to 3 when you want a light touch.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| ksize | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |