Nodes/ComfyUI-ArchiGraph/Threshold πŸ¦β€πŸ”₯
ComfyUI Node

Threshold πŸ¦β€πŸ”₯

Turn a grayscale mess into a clean binary mask

By vincentfsΒ·Created 2 years agoΒ·Updated 9 months agoΒ· 3
Threshold πŸ¦β€πŸ”₯
  • nparrays
  • dst
β—„thresh127β–Ί
β—„maxval255β–Ί
β—„typeBINARYβ–Ί

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 - maxval if above the threshold, else 0
  • BINARY_INV - inverted: 0 above, maxval below
  • 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, default 127. This is the knob you'll actually tune.
  • maxval - the value assigned to the "on" side, 0–255, default 255. Only matters for BINARY / BINARY_INV.
  • type - one of the five above, default BINARY.

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.

CategoryπŸ¦β€πŸ”₯ ArchiGraph/πŸ“€ OpenCV

Inputs (4)

NameTypeDefaultDescription
nparraysNPARRAYβ€”
threshFLOAT1270–255Threshold value.
maxvalFLOAT2550–255Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV thresholding types.
typeCOMBOBINARYThresholding type.

Outputs (1)

NameTypeDescription
dstNPARRAYβ€”