cv2.sqrt
Cv2.sqrt is a gamma curve in disguise — and a quantizer if you feed it an IMAGE
- src
- nparray
Square root is the most boring image operation imaginable, and that is exactly why it shows up in the middle of chains: it undoes a square. Magnitude is a sum of squares, so sqrt closes that loop. A local mean-square map turns into an RMS map with it. And applied to a normalised image it is a gamma curve - sqrt(x) on 0..1 is gamma 0.5, the classic shadow-lifting brighten.
None of that requires a diffusion pass, and that's the point of this whole layer: a power curve is a power curve, free and deterministic. The trick with cv2.sqrt is knowing which side of the 8-bit line you're standing on.
This node is one of ~470 auto-generated raw cv2.* wrappers in ComfyUI CV (bmad4ever/comfyui_cv) - the cv2 call mapped onto sockets, nothing added. The pack says plainly that these wrappers are LLM-generated and uncurated.
The 8-bit problem
cv2.sqrt does not normalise, does not scale, and does not check. It takes the square root of the number that's actually in the array. Link a ComfyUI IMAGE and the wrapper converts it to 8-bit BGR: your pixels are 0..255, so sqrt(255) is 15.97, and it lands in an 8-bit array. Everything above about 16 collapses into a handful of levels. You get a dark, banded, useless image - not because the node is broken, but because the maths happened in the wrong space.
Do it properly and it's clean: Image → CV Array with the float32 (0-1) dtype, then cv2.sqrt, then CV Array → Image. Now the square root is a real curve, and the round trip back to IMAGE rescales 0..1 to 0..255 for you. If you're already in ndarray land - after cv2.magnitude, after cv2.subtract, after cv2.sumElems-adjacent arithmetic - skip the conversions entirely. That's the natural habitat.
Inputs and outputs
src takes NPARRAY, IMAGE or MASK. It's a one-input node: no kernel, no sigma, no threshold, no flags. src's own tooltip says "input floating-point array", which is the author telling you the same thing more politely.
The single output is nparray, always an NPARRAY. The node does not echo the input's nature, so plugging an IMAGE in still gets you an ndarray out and you convert back deliberately. Batches are handled: cv2.sqrt is in the pack's per-frame list, so an IMAGE batch is looped frame by frame and the results re-stacked - a 30-frame clip comes back as 30 processed frames, one call, no per-frame pile of nodes.
What people use it for
In this pack's own examples it's a maths step rather than a look: it appears in the anisotropic-segmentation, RAPID tracking, and AR-model-annotation workflows, in each case closing a squared quantity into a real magnitude. Anywhere you have a variance, an energy or a distance-squared map, this is what turns it into something with units you can threshold.
Two gotchas worth knowing before you file a bug. Negative inputs produce NaN, not an error - sqrt of a negative is undefined and cv2 will happily hand you the wreckage, so gate signed gradient fields through abs first (cv2.absdiff, or CV Cast Array). And cv2 refuses mixed operand types in arithmetic: a float32 output fed into a float64 chain throws, so normalise with CV Cast Array rather than assuming numpy's promotions.
Installing the pack
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
cd comfyui_cv && pip install "opencv-contrib-python-headless~=5.0.0.93"
Manager → search ComfyUI CV does the same thing with a restart. You need Python ≥ 3.12 and a ComfyUI with the V3 node API; older installs simply won't list the nodes. The wheel must be contrib - all OpenCV distributions share one site-packages/cv2, and installing plain opencv-python on top empties the contrib submodules (tools/repair_opencv_contrib.py --check/--apply). Pinned to 5.0.0.93, and the author explicitly does not promise fixes.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY,IMAGE,MASK | input floating-point array. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |