Nodes/opencv-comfyui/OpenCV exp_0
ComfyUI Node

OpenCV exp_0

The exponential node — a math utility, not an image effect

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV exp_0
  • src
  • dst
  • nparray

Let's be upfront: exp_0 is not an image filter in the way equalizeHist or erode are. It's cv2.exp - the element-wise exponential - applied to your nparray. Every pixel value x becomes e^x. That's the whole node. It's the math primitive hiding inside OpenCV's core module, and it got a ComfyUI wrapper when opencv-comfyui (geroldmeisinger/opencv-comfyui) auto-generated nodes for every standalone cv2 function. Its twin exp_1 is identical.

So when would you actually want it? Three real situations:

  1. Log/exp pairs in image math. OpenCV has a matching log function in the pack. log then exp is a classic pair for manipulating values in a compressed (logarithmic) domain and then restoring them - a common trick in HDR and tone-mapping work, where you do arithmetic on log-brightness instead of raw brightness.
  2. Working on float arrays, not display pixels. If you're processing exposure or light data that lives in a float nparray - the kind of thing you'd feed into a tone-mapping stage - exp lets you apply an exponential curve as part of the pipeline.
  3. Recovering values after a log(). If something upstream compressed data with a logarithm, this is how you get back to linear.

The catch that bites everyone: don't run exp on a normal 8-bit image. A uint8 pixel holding value 10 becomes e^10 ≈ 22,026 - which overflows or saturates instantly. exp is for float data and math pipelines, not for pretty pixels.

Inputs and outputs

  • src (NPARRAY) - your array (ideally float).
  • dst (NPARRAY, optional) - OpenCV out-parameter; leave it unconnected, per the pack README.
  • Output: nparray - the element-wise e^x result.

Wiring it up

Straight in and out: nparray in, nparray out. Remember the pack works in nparray space, so you convert with Image2Nparray on the way in - and if your image is uint8, convert to a float representation first (a raw uint8 image through cv2.exp is a garbage generator). The output isn't necessarily a displayable image either, so Nparrays2Image may complain with the pack's 'NoneType' object has no attribute 'shape' if you feed it a non-image array. If you just want an exponential-looking curve on a visible image, you're better off with a gamma or tone-curve node in a post-processing pack - this node is the bare math.

Install

ComfyUI Manager (search "opencv-comfyui") or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, then restart. Dependencies: opencv-contrib-python, numpy, torch; no model downloads. Pack gotchas apply - batch_size-1 images only, and the author's "Expect dragons!" warning about the raw auto-generated interface.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY