[XviD-devel] PSNR question/bug
Marco "elcabesa" Belli
xvid-devel@xvid.org
Sat, 25 Jan 2003 15:11:33 +0100
looking inside image.c i found psnr fouction, after calc of sum of (diff)^2
you make psnr_y=255*255/result
andthen SNR = 10 log10(psnr_y)
is this right??
isn't better do
psnr_y =sum (diff)^2
s= sum (original pixel) ^2
snr= s/psnr;
SNR =10 log10(snr);
a code doing this is this
image_psnr(IMAGE * orig_image,
IMAGE * recon_image,
uint16_t stride,
uint16_t width,
uint16_t height)
{
int32_t diff, x, y, quad = 0;
uint8_t *orig = orig_image->y;
uint8_t *recon = recon_image->y;
float psnr_y;
float s=0;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
diff = *(orig + x) - *(recon + x);
quad += diff * diff;
s+=*(orig + x)**(orig + x);
}
orig += stride;
recon += stride;
}
psnr_y = quad;
if (psnr_y) {
psnr_y = s/psnr_y;
psnr_y = 10 * (float) log10(psnr_y);
} else
psnr_y = (float) 99.99;
return psnr_y;
}