OpenCV PSNR_0
How damaged is that image really? Measuring quality with OpenCV PSNR_0
- src1
- src2
- float
PSNR_0 answers the question "how close is this image to that reference?" with a single number - the Peak Signal-to-Noise Ratio, in decibels. It's cv2.PSNR, and for a ComfyUI user it's one of the most genuinely useful nodes in the whole opencv-comfyui pack, because it turns "did this pass make things better or worse?" into something measurable instead of something you squint at.
The mechanism is dead simple. Both images must be identical in size and type. The node computes the mean squared error (MSE) between them, then converts to dB:
PSNR = 10·log10(R² / MSE)
where R is the maximum possible pixel value. Higher is better. Around 30 dB is "noticeable but not awful" degradation; 40 dB+ is visually excellent; anything below ~20 dB means you've mangled the image. If the two inputs are identical, MSE is zero and PSNR blows up to infinity - which the OpenCV implementation conveniently reports as 99 dB rather than crashing.
The three inputs
src1,src2(NPARRAY) - the two images to compare. Same dimensions, same channel count, or you'll get a size-mismatch assertion. Same type too - compare like with like.R(FLOAT) - the max pixel value, and the field people get wrong. If your arrays are 0..255 uint8,Ris255. If they're 0..1 float,Ris1.0. Mix those up and the reported dB is meaningless (use255with float data and you'll read an inflated score).
The output is a single float in dB. And because the pack can't know your data range, R is on you - the README's "expect dragons" applies right here.
What you'd actually use it for
The killer use case: measuring a post-processing pass honestly. Ran an upscaler or a denoiser? Split your pipeline so one branch keeps the original, run the other through the pass, and compare with PSNR_0. Now "is this sharper or just different?" becomes a number you can actually act on - and compare across settings. Same trick works for compression, color grading, or checking that a mask edit didn't nuke the unedited region.
Install and gotchas
Install the pack once - 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 src1 and src2 come in via Image2Nparray (batch size 1 only - use ImageFromBatch length 1 if it complains). If you get a size assertion, it almost always means the two images don't match - crop or resize one side first.
The honest caveat
PSNR is a useful sanity metric, not a quality oracle. It measures pixel-level agreement, and it famously correlates poorly with human perception - an image can score high PSNR and look worse, because PSNR punishes noise and spatial shifts but is blind to structure and aesthetics. Use it to catch regressions and compare settings, not to declare one image "better." And if the two images aren't supposed to match pixel-for-pixel (say, a regenerated image vs. its seed-mutated cousin), PSNR is the wrong tool - that's a perceptual-metric job, not this node. For what it does measure, though, it's precise, instant, and free. There's also a PSNR_1 twin that's identical; pick either.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| R | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |