OpenCV blendLinear_0
BlendLinear is the per-pixel version of alpha you didn't know you wanted
- src1
- src2
- weights1
- weights2
- dst
- nparray
A plain image blend gives you one global slider: 70% of image A, 30% of image B, everywhere. OpenCV blendLinear_0 is the version where every pixel gets its own slider. Instead of two scalar alpha values it takes two weight images - weights1 and weights2 - and computes src1 * weights1 + src2 * weights2 per pixel. That's the difference between fading two images together evenly and making the transition follow something: a gradient, a mask, a depth map, whatever shape you want the seam to take.
It's the right tool for the composites where a flat alpha leaves a visible line. Post-processing lore - the layer that's "almost none of this is AI," deterministic pixel math - is full of jobs like this: blending an inpainted patch into its surroundings, fading a subject into a new background, stitching tiles so edges agree. Reach for blendLinear when the blend needs to vary across the frame and a constant opacity will show the join.
It's part of opencv-comfyui, the auto-generated pack wrapping all of OpenCV's standalone functions. The node is a straight pass-through to cv2.blendLinear(src1, src2, weights1, weights2, dst). The _0 suffix is overload numbering - blendLinear_1 is the sibling overload and behaves identically in practice.
Inputs that matter
- src1 / src2 - the two
NPARRAYimages. Same size, same channel count, same BGRuint8conventions as the rest of the pack: convert withImage2Nparrayfirst. - weights1 / weights2 -
NPARRAY, same size as the sources (a single-channel weight image is fine and is the usual case). This is the whole point of the node: the weight images are the spatially varying alpha. If you wire two flat all-white/all-black images you've reinvented a constant blend; a gradient weight is where this gets interesting. - dst (optional) - the out-parameter again. Leave it unwired and let OpenCV allocate.
Output: one blended nparray, ready for Nparrays2Image.
Install and gotchas
ComfyUI Manager, search opencv-comfyui; or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. The pack needs opencv-contrib-python, which you likely already have from some other custom node.
The pack README is blunt: these nodes are auto-generated, "ugly and complex to use." The traps are the usual ones - batch size 1 only (slice with ImageFromBatch), and every input is an NPARRAY, so BGR vs RGB is on you. Also, weight images and sources must match in size and type; a size mismatch is the fastest way to an assertion error. And don't expect the weights to be normalized for you - weights1 and weights2 don't need to sum to 1 per pixel, but if they don't, the result clips toward white or black. It's on you to keep them sensible.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| weights1 | NPARRAY | — | |
| weights2 | NPARRAY | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |