psnr

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 3 Imported by: 0

README

PSNR for Go

WIP

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Image

func Image(left, right image.Image) (float64, error)

Image computes the PSNR, in decibels, between two equal-bounds images, treating each pixel as 4 RGBA channels (see psnr's doc comment for the alpha-inclusion rationale).

When both images are *image.RGBA, their Pix bytes are read directly, skipping the At()/color.Color conversion on every pixel: image.RGBA already stores alpha-premultiplied 8-bit channels, which is exactly what At(x, y).RGBA() would widen to 16-bit and this package truncates back down to 8-bit — so the fast path is byte-identical to the general path for that type. Other concrete types (e.g. *image.NRGBA, which stores non-premultiplied channels and would change what's being measured if read raw) fall back to the At()-based loop.

func PSNR

func PSNR(a, b []byte) (float64, error)

PSNR computes the peak signal-to-noise ratio, in decibels, between two equal-length RGBA pixel buffers (4 bytes per pixel: R, G, B, A). Higher is more similar; identical inputs report +Inf, matching the conventional definition of PSNR for a zero mean squared error.

Alpha is included in the error term with the same weight as color, generalizing the standard 3-channel RGB PSNR formula to 4 channels: dividing by len(a) (== 4 * width * height) rather than 3 * width * height. This is a whole-buffer fidelity metric, not a perceptual one.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL