Nodes/opencv-comfyui/OpenCV computeECC_0
ComfyUI Node

OpenCV computeECC_0

A single number that says 'these two images are this aligned' (OpenCV computeECC_0)

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV computeECC_0
  • templateImage
  • inputImage
  • inputMask
  • float

How do you tell if an image alignment actually worked? You could eyeball it, but "it looks right" isn't a number you can branch on. computeECC_0 gives you the number: it computes the Enhanced Correlation Coefficient between two images and hands it back as a float. It's the score function behind OpenCV's image-registration algorithm, exposed as a standalone node.

What it is

computeECC is the objective that findTransformECC maximizes while aligning two images - and both are in this pack, which is convenient. Where findTransformECC_0 finds the warp that aligns image A to image B, computeECC_0 just measures how well A and B already match. One is a solver, the other is a report card.

The score lives in roughly [-1, 1]; 1 means the images match perfectly after intensity normalization. It's more robust than naive pixel difference or cross-correlation to lighting changes, because it operates on a normalized, gradient-aware criterion - that's the "enhanced" part.

The inputs and outputs

  • templateImage (NPARRAY) - the reference image.
  • inputImage (NPARRAY) - the image you're scoring against it.
  • inputMask (NPARRAY, optional) - restrict the computation to a region. Skip it to start.
  • Output: float - the ECC score.

Both images must be the same size; the function is designed around single-channel (grayscale) input, which is the happy path. Feed it an unaligned pair and you'll get a low score; feed it the aligned pair and it climbs toward 1. Same-size requirement - I'll repeat it because it's the one that bites - or you get a size assertion instead of a number.

Where it fits

The realistic ComfyUI use: you're registering frames - stabilizing a video, aligning a render to a template, checking whether a warp node improved things. Run computeECC_0 before and after, and now you have a number you can feed into a comparison or a "did this step help" branch in your graph. It's a measurement node, so don't try to preview the output as an image; wire the float into logic instead. If your inputs are BGR from Image2Nparray, convert to grayscale (cvtColor with code=6 per the README) to stay on the designed path and dodge the CV_8UC1 assertion.

Install and gotchas

Standard for the pack: ComfyUI Manager (search "opencv-comfyui") or

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

Needs opencv-python-contrib. The practical traps: mismatched image sizes (assertion), feeding a multi-channel BGR image when the function wants grayscale (the README's (-215:Assertion failed) img.type() == CV_8UC1 error), and expecting a picture out of a scalar score. Respect the types and this is one of the cleanest little nodes in the pack.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
templateImageNPARRAY
inputImageNPARRAY
inputMaskoptNPARRAY

Outputs (1)

NameTypeDescription
floatFLOAT