From 1abc54cf21db096d716d585743bea787f1dbf510 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 22 Oct 2012 19:01:03 -0400 Subject: [PATCH] Make sure to take alpha into account when computing PSNR --- Core/src/Image.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/src/Image.cpp b/Core/src/Image.cpp index fb94f4a..66d516b 100644 --- a/Core/src/Image.cpp +++ b/Core/src/Image.cpp @@ -80,15 +80,17 @@ double Image::ComputePSNR(const CompressedImage &ci) const { const unsigned char *pixelDataRaw = m_PixelData + i; const unsigned char *pixelDataUncomp = unCompData + i; - double dr = double(sad(pixelDataRaw[0], pixelDataUncomp[0])) * wr; - double dg = double(sad(pixelDataRaw[1], pixelDataUncomp[1])) * wg; - double db = double(sad(pixelDataRaw[2], pixelDataUncomp[2])) * wb; - + double rawAlphaScale = double(pixelDataRaw[3]) / 255.0; + double uncompAlphaScale = double(pixelDataUncomp[3]) / 255.0; + double dr = double(sad(rawAlphaScale * pixelDataRaw[0], uncompAlphaScale * pixelDataUncomp[0])) * wr; + double dg = double(sad(rawAlphaScale * pixelDataRaw[1], uncompAlphaScale * pixelDataUncomp[1])) * wg; + double db = double(sad(rawAlphaScale * pixelDataRaw[2], uncompAlphaScale * pixelDataUncomp[2])) * wb; + const double pixelMSE = (double(dr) * double(dr)) + (double(dg) * double(dg)) + (double(db) * double(db)); - + //fprintf(stderr, "Pixel MSE: %f\n", pixelMSE); MSE += pixelMSE; }