二值化
The FlowCV Threshold node, explained
- 图像输入
- 图像输出
Thresholding is the "make it black and white" button, and it's the boring workhorse behind half of computer-vision pipelines. FCV_Threshold (labeled 二值化 in the menu) is FlowCV's take on it: a fixed-value threshold that slams every pixel into one of two buckets. You reach for it when you want a clean binary mask to drive something downstream - finding rectangles, feeding an edge detector, or building a mask for an inpainting pass - and you want it done with plain OpenCV instead of the usual ComfyUI prepackaged preprocessors.
FlowCV is a small, Chinese-labeled OpenCV wrapper pack for ComfyUI. Every node in it works in CVIMAGE space: a raw OpenCV numpy array in BGR order, not ComfyUI's IMAGE tensor. So this node takes a CVIMAGE and hands you back a CVIMAGE. To actually see the result or feed it to a diffusion model, you pipe it through FCV_CVToIMAGE afterward. That's the one wiring detail that trips everyone up on first use.
How it works
Internally this is a straight cv2.threshold() call. The node first converts your image to grayscale if it isn't already, then applies the fixed threshold you set: pixels above it get the max value, everything else goes to zero. There's a 阈值类型 (threshold type) dropdown with five modes - 二值化 (binary), 反向二值化 (binary inverted), 截断 (truncate, pixels above threshold get clamped to it), and two "threshold to zero" variants that zero out one side of the histogram instead of making everything strictly black-and-white. The last two are handy when you want to preserve gradient detail rather than flatten it.
One thing to know: even though the output is conceptually binary, the node converts it back to a 3-channel BGR image so it stays compatible with the rest of the pack. Grayscale in, "grayscale" that's secretly 3 channels out.
The inputs that matter
You'll set two things 95% of the time:
- 阈值 (threshold, default 127) - the cutoff. 0–255.
- 阈值类型 (threshold type, default 二值化) - binary, inverted, or one of the softer modes.
The third input, 最大值 (max value, default 255), is the value assigned to pixels that pass - leave it at 255.
The 阈值类型 tooltips are the author's own descriptions, so trust them over intuition: 反向二值化 is what you want when your mask comes out inverted - black text on white instead of the other way round.
Installing FlowCV
The pack is available in ComfyUI Manager - search "FlowCV". Or install by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Koren-cy/FlowCV
Restart ComfyUI. The only real dependencies are opencv-python, numpy, and pyserial - nothing heavy, no model downloads. One heads-up: the README says the project has migrated to ComfyUI_For_Academic, so this repo is effectively in archive mode. It works, but don't hold your breath for bug fixes here.
Where people get burned
The big one: if you connect a CVIMAGE straight into a normal ComfyUI preview node, the colors will look wrong or the connection just won't exist - the wire types are different. Run every CVIMAGE through FCV_CVToIMAGE before anything standard touches it. Also, FlowCV nodes swallow errors: if something fails, they print a Chinese error to the ComfyUI console and hand back your input unchanged. If a workflow "does nothing," check the console, not the canvas.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像输入 | CVIMAGE | 输入的openCV格式图像 | |
| 阈值 | INT | 1270–255 | 二值化的阈值,像素值大于此值的设为最大值,否则设为0 |
| 最大值 | INT | 2551–255 | 分配给满足条件的像素值的最大值 |
| 阈值类型 | COMBO | 二值化 | 阈值处理类型:二值化、反向二值化、截断(大于阈值的设为阈值)、阈值归零(小于阈值归零)、反向阈值归零(大于阈值归零) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 图像输出 | CVIMAGE | 一般二值化处理后的图像 |