ComfyUI Node

cv2.exp

It's e^x, and that matters

By bmad4ever·Created 4 months ago·Updated 14 days ago· 1
cv2.exp
  • src
  • nparray

Every so often someone reads cv2.exp as "exposure" and wires their image into it. Do that and you'll get a white rectangle, because this node is the element-wise exponential - e^x, applied to every value in the array - and an 8-bit image lives in 0..255, where e^6 is already 403 and anything brighter clips instantly. It's a matrix-maths node that happens to accept pictures. Useful once you see the right shape of pipeline for it.

What it does

src takes an IMAGE, MASK or NPARRAY, and the output is always a plain NPARRAY named nparray - this isn't a displayable image until you bridge it. On the values themselves: 0 stays 1, 1 becomes 2.718, negative inputs compress toward zero. That monotonic curve is the whole content of the node, and its meaning depends entirely on what range your data is in. On a 0..1 float tensor it's a strong, non-linear lift. On 0..255 uint8 it's saturation. On a distance field or a score map it's a shaping function.

Note what's missing: there is no base parameter, no scaling, no clamp. If you wanted a * e^(b*x) you compose it from the arithmetic wrappers around this node, or you use a gamma/exposure node instead - post-processing.md makes the point that exposure changes are properly power or additive operations, and this is neither.

Where an exponential is actually the right tool

Three real cases:

Closing a log-domain pipeline. Any filter applied in log space has to be undone, and the undo is exp. The classic version is homomorphic filtering - log → filter → exp - where working in the log domain turns a multiplicative illumination field into an additive one you can subtract. This node is the second half of that, and any node pack claiming a neat illumination-correction recipe usually has one of these hiding inside it.

Turning a squared distance into a Gaussian. A squared-distance or squared-error map becomes an unnormalised Gaussian weight by exponentiating the negative, which is how you hand-roll bilateral/guided-style weighting or an exponential falloff mask from a distance transform.

Anywhere the data already lives in a log or dB-ish scale. Decibel values, log-likelihood scores, log-probabilities - reading them out means exponentiating, and the pack's array-statistics and inspection nodes are how you check the range before and after.

Reading the output

Because the result is a raw NPARRAY, the sensible next hop is CV Array To Numbers (to see actual values), CV Array Statistic (to check min/max), or Preview CV Array for a look. CV Array → Image will show it too, and there's the trap: that conversion min-max normalises floats by design, so a result whose values range 1.0 to 1.05 will display as a full-contrast picture and you'll conclude the maths did something dramatic. Preview CV Array lets you choose normalise versus raw, which is the honest way to look at a shaped field.

An IMAGE input also gets frame 0 unless the op is on the pack's batch-safe list - check the tooltip on src if you're feeding a batch and care. For a one-frame conversion path, Image → CV Array with an explicit dtype is more predictable than relying on the implicit bridge, because you're deciding whether the numbers entering exp are 0..1 or 0..255. That choice, not the node, decides whether you get a curve or a white screen.

Installing it

It comes with the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Or find comfyui_cv in ComfyUI Manager and restart. Needs Python ≥ 3.12 and a recent V3-API ComfyUI. You'll find it under image/CV/low-level/cv2 E, one of ~470 generated wrappers.

Traps

Saturation on integer input is the headline one - the node is for float arrays and will not warn you. Overflow to inf is the other: exp of a value above ~88 in float32 is infinite, and then every downstream operation propagating that is quietly wrong until something displays a black or white blob. Check with CV Inspect CV Data before you trust a shaped field. And don't confuse this with cv2.pow, which is where gamma lives if what you actually wanted was a contrast curve.

Categoryimage/CV/low-level/cv2 E

Inputs (1)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASKinput 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)

NameTypeDescription
nparrayNPARRAY—