OpenCV addWeighted_0
Blend two images with weights — OpenCV addWeighted_0
- src1
- src2
- dst
- nparray
addWeighted_0 is the blend node, and it's one of the genuinely reach-for-it members of this pack. It computes dst = alpha * src1 + beta * src2 + gamma: each pixel of the first image scaled by alpha, each pixel of the second scaled by beta, added together, plus a constant offset. Set alpha + beta = 1 and you have a clean crossfade between two images - the exact recipe for fading one render into another, blending an upscaled pass with its original, or mixing a texture with its mask.
That last step is where people usually land: with alpha between 0 and 1, this is the deterministic way to blend two aligned images "90% of A, 10% of B" without any generative nonsense in the middle. It's fast, it's exact, and it never changes your seed. The post-processing layer this pack lives in is all about those millisecond, no-model operations, and this is one of the clearest examples.
How it works
cv2.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]]). Both images must be the same size and type. The scalar alpha weights src1, beta weights src2, and gamma is a brightness offset added to every pixel. The classic "normal blend" uses alpha + beta = 1 with gamma = 0; if they sum to more than 1 you brighten, less than 1 you darken. dtype is the output type, and -1 (same as inputs) is the sane default for image work. The optional dst is the OpenCV out-parameter - the README tells you to skip those and read the return value.
The mechanism is worth internalizing because it's also the formula behind a thousand "adjustment" nodes elsewhere: any time you see "mix by amount", it's this math wearing a different name. Knowing the primitive means you can stop hunting for a specialized node and just build the blend yourself.
The inputs that matter
- src1 / src2 (NPARRAY) - the two images to blend.
- alpha (FLOAT) - weight of src1.
- beta (FLOAT) - weight of src2.
- gamma (FLOAT) - constant added to every pixel; 0 for a pure blend.
- dtype (INT) -
-1= same type as inputs. - dst (NPARRAY, optional) - skip it.
Output: one nparray - the blended image.
Wiring it up
Standard chain: IMAGE → Image2Nparray → addWeighted_0 → Nparrays2Image. Feed the same IMAGE into both src inputs with alpha = 2, beta = -1, gamma = 0 and you get an unsharp-mask-ish contrast pop; feed two different renders with alpha animated and you've got a crossfade you can keyframe. Batch_size is limited to 1, so slice video batches with ImageFromBatch first.
Installing opencv-comfyui
ComfyUI Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Restart. Dependency: opencv-contrib-python (you likely already have it).
Gotchas
- Size mismatch - src1/src2 must match, or OpenCV asserts.
alpha + betamatters - > 1 brightens, < 1 darkens; if your "blend" looks like a white wash, your weights sum wrong.- Batch_size == 1 - use
ImageFromBatch.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| alpha | FLOAT | — | |
| src2 | NPARRAY | — | |
| beta | FLOAT | — | |
| gamma | FLOAT | — | |
| dtype | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |