Refactor PSNR calculations.

This commit is contained in:
Pavel Krajcevski 2013-09-26 20:18:26 -04:00
parent 264e447e80
commit 36ce478821

View File

@ -174,43 +174,41 @@ double Image::ComputePSNR(const CompressedImage &ci) const {
return -1.0f; return -1.0f;
} }
const double wr = 1.0; // const double w[3] = { 0.2126, 0.7152, 0.0722 };
const double wg = 1.0; const double w[3] = { 1.0, 1.0, 1.0 };
const double wb = 1.0;
double MSE = 0.0; double mse = 0.0;
for(uint32 i = 0; i < imageSz; i+=4) { for(uint32 i = 0; i < imageSz; i+=4) {
const unsigned char *pixelDataRaw = m_PixelData + i; const unsigned char *pixelDataRaw = m_PixelData + i;
const unsigned char *pixelDataUncomp = unCompData + i; const unsigned char *pixelDataUncomp = unCompData + i;
double rawAlphaScale = double(pixelDataRaw[3]) / 255.0; float r[4], u[4];
double uncompAlphaScale = double(pixelDataUncomp[3]) / 255.0; for(uint32 c = 0; c < 4; c++) {
double dr = double(sad(rawAlphaScale * pixelDataRaw[0], uncompAlphaScale * pixelDataUncomp[0])) * wr; if(c == 3) {
double dg = double(sad(rawAlphaScale * pixelDataRaw[1], uncompAlphaScale * pixelDataUncomp[1])) * wg; r[c] = pixelDataRaw[c] / 255.0;
double db = double(sad(rawAlphaScale * pixelDataRaw[2], uncompAlphaScale * pixelDataUncomp[2])) * wb; u[c] = pixelDataUncomp[c] / 255.0;
} else {
const double pixelMSE = r[c] = static_cast<double>(pixelDataRaw[c]) * w[c];
(double(dr) * double(dr)) + u[c] = static_cast<double>(pixelDataUncomp[c]) * w[c];
(double(dg) * double(dg)) + }
(double(db) * double(db)); }
//fprintf(stderr, "Pixel MSE: %f\n", pixelMSE); for(uint32 c = 0; c < 3; c++) {
MSE += pixelMSE; double diff = (r[3] * r[c] - u[3] * u[c]);
mse += diff * diff;
}
} }
MSE /= (double(GetWidth()) * double(GetHeight())); mse /= GetWidth() * GetHeight();
double MAXI = const double C = 255.0 * 255.0;
(255.0 * wr) * (255.0 * wr) + double maxi = (w[0] + w[1] + w[2]) * C;
(255.0 * wg) * (255.0 * wg) + double psnr = 10 * log10(maxi/mse);
(255.0 * wb) * (255.0 * wb);
double PSNR = 10 * log10(MAXI/MSE);
// Cleanup // Cleanup
delete unCompData; delete unCompData;
return PSNR; return psnr;
} }
void Image::ConvertToBlockStreamOrder() { void Image::ConvertToBlockStreamOrder() {