Nodes/opencv-comfyui/OpenCV absdiff_1
ComfyUI Node

OpenCV absdiff_1

OpenCV absdiff_1

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

Here's the thing you need to know up front about absdiff_1: it does exactly the same job as absdiff_0, and its inputs are identical. src1 and src2 in, an |src1 - src2| nparray out. The _1 is just OpenCV's overload number, not a different behavior. opencv-comfyui parses every overload it finds in cv2's type definitions and gives each one a numbered node, and for absdiff the two overloads happen to have the same signature. So if absdiff_0 is in your palette, absdiff_1 is a duplicate you can safely ignore - or pick whichever one you landed on first.

What it's for

Use it to measure change: diff two frames of a video to expose the moving bits, diff an image before and after an operation to verify the edit, or diff two overlapping tiles to find the seam where they disagree. Because it takes the absolute value, it scores dark-to-bright and bright-to-dark changes equally, so it's direction-agnostic by design. Bright pixel = big difference, black = no difference.

The honest framing: this is a workhorse primitive, not a magic bullet. It tells you where things differ, not what the difference means - that part is your job, usually with a threshold or a blur downstream. But when you need "what changed" answered in a couple of milliseconds without burning a diffusion pass, this is the tool.

The inputs that matter

  • src1 / src2 (NPARRAY, both required) - the images to compare. Same size, same channel count.
  • dst (NPARRAY, optional) - the out-parameter OpenCV lets you write into. The pack's README tells you to skip optional dst inputs and read the return value instead. Leave it alone.

Output is a single nparray with the difference map.

Wiring it up

Standard opencv-comfyui chain: IMAGEImage2Nparrayabsdiff_1Nparrays2ImageIMAGE. Both conversion nodes are single-batch only, so if your input is a video batch, pull one frame out with ImageFromBatch (length=1) first.

One genuinely useful downstream move: take the absdiff output, blur it, and threshold it - now you have a motion/change mask you can feed into an inpainting or compositing step. That turns a trivial math node into the front end of a real pipeline.

Installing

Same as every node in this pack. ComfyUI Manager → search "opencv-comfyui", or:

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

Restart ComfyUI. It depends on opencv-contrib-python (plus numpy and torch), and you usually already have OpenCV in your environment from another pack:

pip install opencv-contrib-python

Gotchas

  • Batch error - the conversion nodes only accept batch_size == 1; split batches with ImageFromBatch.
  • Shape mismatch assertion - the two inputs must be the same size. Resize first.
  • Solid black result - either the inputs are truly identical or one of them isn't an image-shaped array at all. A 1-D float array will sail through the type system and then disappoint you.
Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY