OpenCV PSNR_1
PSNR_1 — a honest before/after metric for your upscale and denoise passes
- src1
- src2
- float
First, the disclaimer so you don't waste time hunting for a difference: PSNR_1 and PSNR_0 are the same node. The opencv-comfyui pack generates one per OpenCV overload, cv2.PSNR got generated twice, and the twins are behaviorally identical - src1, src2, R in, a single float in dB out.
So this article is really about the practice: how to use PSNR as a measurement tool in a ComfyUI workflow, because that's where the value is.
The metric, in one breath
PSNR compares two same-size images pixel-by-pixel: it computes the mean squared error between them, then converts to decibels via 10·log10(R²/MSE), where R is the max pixel value. Higher = closer. ~40 dB is excellent, ~30 dB is okay, sub-20 is broken. Identical images give you 99 dB (OpenCV clamps the infinity).
The one knob that matters is R: 255 for 0..255 uint8 arrays, 1.0 for normalized 0..1 float arrays. This is the pack README's "expect dragons" made concrete - the node can't guess your range, and the wrong R silently inflates or deflates every score.
The practice: measure your upscaler honestly
Here's the workflow shape that makes this node worth having. The whole point of an upscaler or denoiser is fidelity to the source, and "fidelity" is exactly what PSNR measures. So:
- Load your source image.
- Run it through your upscale/denoise pass.
- Feed the original into
src1and the processed result intosrc2.
But wait - PSNR requires equal dimensions. An upscaler makes the image bigger, so you must downscale the upscaled result back to the original size before comparing (or upscale the original too). Otherwise you get a size-mismatch assertion and learn nothing. Once they match, the number tells you whether your new settings are holding the source or hallucinating wildly.
The same trick works for denoise settings, compression levels, and color-grading passes. It's deterministic, instant, and - unlike eyeballing two preview images side by side - it gives you a number you can compare across a dozen parameter sweeps.
Install and the usual pack routine
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, then pip install opencv-contrib-python. Both inputs come through Image2Nparray (batch size 1 only; ImageFromBatch length 1 fixes the error). Match your array types - comparing a uint8 to a float array is a classic silent-wrong-result trap.
The honest limits
PSNR is blind to aesthetics. It loves identical pixels and punishes any difference equally, so a sharpened image with a slightly different tone curve can score lower than a mushy one that happens to match the original - while your eye says the sharpened one is better. It also hates misalignment: a one-pixel shift craters the score even though the image looks fine. So use it as a regression detector and a settings-comparison tool, not as a judge of "which looks best." For the job it's built for - "did this pass preserve the source?" - it's exactly right, and PSNR_1 is the simplest way to ask that question in ComfyUI.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| R | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |