中值滤波
Median filter in FlowCV
- 图像输入
- 图像输出
Salt-and-pepper noise - those random white and black specks that look like someone spilled pepper on your scan - is exactly what a median filter eats for breakfast. FlowCV's 中值滤波 node (class FCV_Median) is a one-knob tool for it: instead of averaging neighbors like a mean or Gaussian blur, it takes the median value in the window and writes that. A single random white pixel surrounded by sane pixels never wins the median vote, so the speck disappears without dragging the whole neighborhood toward gray.
That property is why this is the node you reach for on noisy scans, video frames, or anything that's been JPEG-crushed into speckles - especially right before thresholding or edge detection, which amplify noise into garbage. The KB's troubleshooting instincts agree: clean the input before you make decisions about it.
How it works
cv2.medianBlur() slides a square window over the image, sorts the values inside, and replaces the center pixel with the middle value. Because a true outlier is never the median, isolated noise vanishes while real structure mostly survives - edge preservation is far better than a mean filter of the same size. It's nonlinear, which is the polite way of saying it behaves differently from the smooth-weighting filters, but in a good way for this job.
One input, 核大小 (kernel size, default 5). It must be odd; the node quietly bumps even values up by one. Bigger = more aggressive (and slower, since each window sort costs). For most speckled images, 3–5 is plenty; only crank it up when the noise is dense.
Wiring it up
CVIMAGE in, CVIMAGE out, like every processing node in the pack. Natural spot in a chain: FCV_Median → FCV_Threshold/FCV_OTSU → FCV_FindRectangles, or FCV_Median → FCV_Canny for a much cleaner edge map. Convert with FCV_CVToIMAGE to preview or hand off to standard ComfyUI nodes.
Installing
It ships in FlowCV - one pack install covers it. ComfyUI Manager, search "FlowCV"; or:
cd ComfyUI/custom_nodes
git clone https://github.com/Koren-cy/FlowCV
Restart ComfyUI. Dependencies: opencv-python, numpy, pyserial, no models to fetch. The README carries a note that the project migrated to ComfyUI_For_Academic, so this repo is in archive mode - it works, it's just not being maintained forward.
Gotchas
Median blur is slower than mean or Gaussian on large kernels, so keep sizes modest on big images. And a filter this cheap can't fix heavy, correlated noise - if the "speckles" are actually fine texture you care about, you've got the wrong tool. Usual pack warning: on any error it prints a Chinese message to the console and returns the input unchanged, so a no-op output means read the terminal.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像输入 | CVIMAGE | 输入的openCV格式图像 | |
| 核大小 | INT | 53–99 | 中值滤波核的大小,必须为奇数。值越大,滤波效果越强 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 图像输出 | CVIMAGE | 中值滤波处理后的图像 |