OpenCV norm_2
How different are two images? The L2/L1 distance, as one number
- src1
- src2
- mask
- float
norm_2 wraps cv2.norm(src1, src2, normType, mask) - the two-array overload that measures the distance between two arrays: norm(src1 - src2). Put two images in, get one number out that says how different they are. It's the closest thing this pack has to a "similarity score", and it's genuinely the most useful of the four norm variants.
What it computes
Behind the scenes OpenCV subtracts src2 from src1 and takes the norm of the difference. With normType:
4= L2: Euclidean distance - the standard "how different" measure, squared-and-rooted.2= L1: Manhattan distance - sum of absolute differences; a bit more forgiving of a single large outlier.1= INF: the single biggest pixel difference - "the worst-case error".
So you can read it as: L2 for overall difference, L1 for total deviation, INF for worst-pixel error. For comparing images, L2 is the one people mean by "difference".
Why you'd reach for it
Concrete workflow uses:
- Frame comparison. Compare frame N to frame N+1 (grab frames from a batch with
ImageFromBatch) - the distance spikes at cuts/scene changes. Feed the float to a threshold and you've got a shot-detector. - Output vs reference. After an edit or an img2img pass, measure how far the result drifted from the input.
- Denoise/blur sanity check. A "denoised" image that's identical to its input scores zero - you'd know your node chain isn't running.
Both inputs must be the same size and dtype (grayscale is typical). The optional mask restricts the comparison to a region - useful if only part of the image should matter.
Inputs and output
src1,src2(NPARRAY) - the two arrays to compare.normType(INT) -4L2,2L1,1INF.mask(optionalNPARRAY).- Output:
float.
The number is only meaningful relative - a "difference" of 5 on a 1024×1024 grayscale image is tiny; the same value on an 64×64 crop is huge. Use it for A/B comparisons within one pipeline, not as an absolute quality metric.
Installing
Part of geroldmeisinger/opencv-comfyui. ComfyUI Manager → "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart. Dependency: opencv-contrib-python.
Troubleshooting
- Size/dtype mismatch - both inputs must match; convert to grayscale (
cvtColorcode 6) and same resolution first. - "Same image gives 0" - correct, that's the point.
- Which variant -
norm_2andnorm_3are identical duplicates (overload residue); use_2. Don't confuse them withnorm_0/norm_1, which take one array.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| normType | INT | — | |
| maskopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |