Nodes/opencv-comfyui/OpenCV adaptiveThreshold_1
ComfyUI Node

OpenCV adaptiveThreshold_1

OpenCV adaptiveThreshold_1

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV adaptiveThreshold_1
  • src
  • dst
  • nparray
maxValue
adaptiveMethod
thresholdType
blockSize
C

adaptiveThreshold_1 is adaptiveThreshold_0 wearing a different number. Same inputs - src, maxValue, adaptiveMethod, thresholdType, blockSize, C, optional dst - same local-threshold binarization, same single nparray output. The overloads this pack parsed from OpenCV produced two entries with identical signatures, so pick one and ignore the other.

Why you'd use it at all

Binarize a grayscale image with a threshold that adapts to local brightness. Unlike a global threshold, it survives uneven lighting - shadows and gradients don't wash whole regions to the wrong side - which makes it the tool for turning soft grayscale inputs (depth maps, masks, rough sketches) into crisp black-and-white line art or binary masks. It's a genuinely useful node in ComfyUI because so much downstream work wants a clean binary signal: ControlNet-style lineart pre-processing, mask cleanup before inpainting, or generating "ink" versions of an image.

The inputs that matter

  • src (NPARRAY) - must be grayscale; BGR input asserts with img.type() == CV_8UC1.
  • maxValue (FLOAT) - the value pixels are set to when they pass; 255 is the norm.
  • adaptiveMethod (INT) - 0 = mean of neighborhood, 1 = Gaussian-weighted mean.
  • thresholdType (INT) - 0 = binary, 1 = inverted (white lines on black).
  • blockSize (INT) - odd window size; 11–21 to start.
  • C (FLOAT) - constant subtracted from the local average; higher C, stronger edges only.
  • dst (NPARRAY, optional) - leave it; the README says to skip out-params.

Output: one nparray - the binary result.

The wiring that works

Image2Nparray → cvtColor (code=6, BGR2GRAY) → adaptiveThreshold_1 → Nparrays2Image. The grayscale→RGB conversion on the way out is automatic, so the result displays normally. Skip the cvtColor and you'll be staring at the pack's most common assertion error. And remember the conversion nodes are batch_size == 1 only.

Installing opencv-comfyui

ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart ComfyUI. Dependency: opencv-contrib-python (you probably have it).

Gotchas

  • Grayscale only - cvtColor (code=6) before this node, always.
  • Odd blockSize - even values throw.
  • Batch_size == 1 - slice batches with ImageFromBatch.
Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
srcNPARRAY
maxValueFLOAT
adaptiveMethodINT
thresholdTypeINT
blockSizeINT
CFLOAT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY