cv2.divide (2/2)
The reciprocal node, argument order and all
- src2
- result
Same verb, opposite shape: this is cv2.divide's scalar-over-array overload - dst = saturate(scale / src2). One number on top, a whole array underneath. Its job in life is producing a reciprocal map, and it's the node you reach for when "invert this" means 1/x rather than "255 minus x".
What it's for
Reciprocal transforms show up more often than you'd think:
- A 1/distance or 1/depth ramp. Feed it a distance field and you get a falloff that's steep near the subject and flattens out - a very different curve from the linear distance ramp, and a cheap way to fake atmospheric weighting.
- Undoing a known multiplier. You multiplied by a gain map; now you want to take it back out.
- Inverse weighting for blending. Two overlapping regions, weight one by 1/other so the pair sums to something sensible.
The most common home for this exact overload is spectrum and deconvolution math, which is where the pack's Fourier playground uses it.
Inputs and outputs
Two widgets, and the order runs the wrong way round from how people read it. scale comes first - it's the numerator - and src2 follows as the denominator. Type 12 and wire an array of 4s and you get 3s. Wire the array first in your head and you'll be confused for ten minutes.
src2 accepts a LATENT as well as IMAGE, MASK and NPARRAY, and the single result output echoes that input's format - the tooltip says so explicitly, which is how a LATENT goes in and a LATENT comes out untouched in value range.
dtype is the output depth, default "same as input". Unlike the array-by-array version there's no depth-matching rule to trip over here, since the numerator is a plain scalar.
Installing comfyui_cv
This is one of roughly 470 auto-generated raw cv2.* wrappers in bmad4ever/comfyui_cv, a GPL-3.0 fork of Gerold Meisinger's opencv-comfyui with a curated node layer on top. Install from ComfyUI Manager by searching ComfyUI CV, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
Then restart. Python ≥ 3.12 and a recent ComfyUI on the V3 node API; the sole dependency is opencv-contrib-python-headless~=5.0.0.93. Use the contrib wheel - all four OpenCV distributions share one site-packages/cv2 and the last install wins, so a later plain opencv-python takes the contrib nodes out with it. tools/repair_opencv_contrib.py --check and --apply exist for that.
Common issues
Infinity and NaN. In float output, dividing by a zero pixel is a real divide by zero, and you get inf. Clamp the denominator away from zero (a tiny cv2.add upstream) if that matters to the next node.
Everything is 255. In uint8, any pixel whose denominator is less than 1 lands above 255 and clips. If small denominators are the interesting part of your image, convert to float first.
Nothing changed on a bad input. Because the scalar path has no depth-matching rule, an accidental uint8 cast upstream can quietly truncate your fractional result to 0 or 1. Check dtype and convert deliberately.
Sanity check first. Feed a constant array and a known scale and confirm the output is what you expect. It takes ten seconds and saves an hour of graph archaeology.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| scale | FLOAT | 0.0000-1e+38–1e+38 | scalar factor. |
| src2 | COMFY_MATCHTYPE_V3 | second input array of the same size and type as src1. The image output(s) echo this input's format. A LATENT link is processed in latent space: frame 0 becomes a float32 [H,W,C] array (any channel count), values untouched. Arithmetic ops (add, multiply, etc.) also accept a full LATENT batch ({samples: [B,C,H,W]}) — the whole batch flows through when both inputs have the same batch size. 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. | |
| dtypeopt | COMBO | same as input | optional depth of the output array; if -1, dst will have depth src2.depth(), but in case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth(). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | COMFY_MATCHTYPE_V3 | Echoes the 'src2' input's format: an IMAGE link comes back as IMAGE, MASK as MASK, NPARRAY stays NPARRAY. |