Threshold π¦βπ₯
Turn a grayscale mess into a clean binary mask
- nparrays
- dst
Threshold is the node that turns "vague brightness" into "this pixel is in, this pixel is out." It applies a single fixed cutoff to every pixel of your array: below the value, one result; above it, another. It's the simplest way to go from a noisy gradient or a soft probability map to a hard decision - and in this pack, it's the natural next step after Sobel.
Why you'd reach for it
A Sobel edge map is a gradient: bright where edges are strong, dim where they're faint, full of intermediate values. Threshold collapses all of that into a clean binary edge map where a line is either present or absent - which is exactly what you want before contour detection, connected-component analysis, or any geometry step. The same logic applies to masks: take a soft confidence map and decide where the mask is actually on. In architectural work, that's the difference between "here's some brightness" and "here's the floor plan."
How it works
It's a direct wrapper over OpenCV's cv2.threshold with a fixed level - no Otsu auto-thresholding here, no adaptive magic. Every pixel of the input is compared against thresh, and the type enum decides what happens to it. The five types are the standard OpenCV set:
- BINARY -
maxvalif above the threshold, else0 - BINARY_INV - inverted:
0above,maxvalbelow - TRUNC - capped at the threshold if above, unchanged below
- TOZERO - above stays, below becomes
0 - TOZERO_INV - the mirror image of TOZERO
Batches are processed frame by frame, and the output keeps the same shape as the input - same dtype too, so a uint8 array in gives a uint8 array out.
The inputs that matter
nparrays- the input array.thresh- the cutoff,0β255, default127. This is the knob you'll actually tune.maxval- the value assigned to the "on" side,0β255, default255. Only matters for BINARY / BINARY_INV.type- one of the five above, defaultBINARY.
Output is dst, an NPARRAY of the same shape.
Installing it
In ComfyUI-ArchiGraph - ComfyUI Manager β search "ArchiGraph" β install β restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph
cd ComfyUI-ArchiGraph
pip install -r requirements.txt # or install.bat / install.sh
Needs the pack's OpenCV stack (opencv-python etc.). If other packs have cv2 version fights, reinstalling this pack's requirements is the usual fix.
Where people get burned
The single most common failure is feeding it the wrong value range. This node assumes 8-bit 0β255 input, which is what AG To Nparray produces. If you wire in a float 0β1 array instead, a threshold of 127 matches nothing and your "mask" comes back all black - every pixel is below it. Scale and convert to uint8 first.
Second, the threshold is global and fixed. There's no auto mode, so a single value has to serve the whole image. If your lighting varies wildly across the image, one cutoff will lose the dim edges or drown in noise - that's a signal to preprocess (blur, normalize) rather than to fight the slider. And remember the output is still an NPARRAY: route it through AG To Image before previewing or saving as a normal image.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| nparrays | NPARRAY | β | |
| thresh | FLOAT | 1270β255 | Threshold value. |
| maxval | FLOAT | 2550β255 | Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV thresholding types. |
| type | COMBO | BINARY | Thresholding type. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| dst | NPARRAY | β |