OpenCV multiply_0
Per-pixel multiply with saturation — gain, dimming, and blend without the math pitfalls
- src1
- src2
- dst
- nparray
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.0is neutral;0.5halves the result.dtype(INT) --1keeps the input type (the normal choice:CV_8Ufor 8-bit images).0forcesCV_8U,5isCV_32F. Use5if you're chaining math and want to avoid intermediate 8-bit rounding.dst(optionalNPARRAY) - 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
src1andsrc2must be the same dtype; if one came from aCV_32Fbranch and the other fromCV_8U, they won't multiply. - Colors look shifted - check your BGR/RGB chain;
Image2Nparrayoutputs BGR, and it must be reversed on the way out. - Everything looks the same -
scale=1.0withsrc2identical tosrc1squares the values, which is a change, just subtle at 8-bit. Tryscale=0.5to see the effect clearly.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| scale | FLOAT | — | |
| dtype | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |