Nodes/opencv-comfyui/OpenCV multiply_0
ComfyUI Node

OpenCV multiply_0

Per-pixel multiply with saturation — gain, dimming, and blend without the math pitfalls

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV multiply_0
  • src1
  • src2
  • dst
  • nparray
scale
dtype

multiply_0 wraps cv2.multiply(src1, src2, dst, scale, dtype) - element-wise multiplication of two arrays with saturation. The formula is dst = saturate(scale * src1 * src2). If you've ever wanted to dim an image, apply a gain, or blend two passes together, this is the clean OpenCV way to do it, and the "saturate" part matters more than you'd think.

Why you'd reach for it

  • Dim/brighten by a factor - multiply the image by a constant.
  • Blend two images - multiply a light pass by a mask, multiply two layers, screen-style composites.
  • Contrast shaping - multiplying an image by itself (src1 = src2) with a small scale gives a nonlinear curve that crushes mids - a poor man's gamma that only moves the exposure, not the white point.

The key difference from doing this in numpy: saturation, not wraparound. In uint8, numpy's * silently wraps 250 * 2 to 244. OpenCV's multiply clamps to 255. That's the difference between a blown highlight and a psychedelic color cast, and it's the reason to reach for this node instead of a math node.

Inputs that matter

  • src1, src2 (NPARRAY) - two arrays, same size and type.
  • scale (FLOAT) - multiplier applied to the product. 1.0 is neutral; 0.5 halves the result.
  • dtype (INT) - -1 keeps the input type (the normal choice: CV_8U for 8-bit images). 0 forces CV_8U, 5 is CV_32F. Use 5 if you're chaining math and want to avoid intermediate 8-bit rounding.
  • dst (optional NPARRAY) - the out-parameter; leave it unconnected.

Output: nparray, ready for Nparrays2Image or the next OpenCV node.

The constant-multiply gotcha

To multiply by a constant you need an NPARRAY holding that constant - and there's no convenient "make a constant array" node in the pack, so wiring a single scalar in is awkward. Two workarounds: multiply the image with itself and scale (src2 = same image, scale < 1 dims it), or multiply two different real images (the common case anyway - you're usually blending a pass with a mask). Don't try to build a constant array by hand; it's not worth it.

Installing

Part of geroldmeisinger/opencv-comfyui. Manager → search "opencv-comfyui", or:

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

restart. Dependency: opencv-contrib-python, already in most setups.

Pipeline and troubleshooting

IMAGE → Image2Nparray → multiply_0 → Nparrays2Image → IMAGE. Image2Nparray flips RGB→BGR and only accepts batch_size==1.

  • "Type mismatch" - both src1 and src2 must be the same dtype; if one came from a CV_32F branch and the other from CV_8U, they won't multiply.
  • Colors look shifted - check your BGR/RGB chain; Image2Nparray outputs BGR, and it must be reversed on the way out.
  • Everything looks the same - scale=1.0 with src2 identical to src1 squares the values, which is a change, just subtle at 8-bit. Try scale=0.5 to see the effect clearly.
Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
scaleFLOAT
dtypeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY