00001 #include "imageUtil.h"
00002
00003 #include <QImage>
00004
00005 using namespace std;
00006 namespace Color {
00007 const Real
00008 YCbCrCoeffs[][4]= {
00009 { 0.299, 0.587, 0.114, 0 },
00010 {-0.168736, -0.331264, 0.5, 0.5 },
00011 { 0.5, -0.418688, -0.081312, 0.5 },
00012
00013 { 1, 1, 1, 0 },
00014 { 0, -0.34414, 1.772, -0.5 },
00015 { 1.402, -0.71414, 0, -0.5 }
00016 },
00017 RGBCoeffs[][4]= {
00018 {1,0,0,0}, {0,1,0,0}, {0,0,1,0},
00019 {1,0,0,0}, {0,1,0,0}, {0,0,1,0}
00020 };
00021
00022 vector<Real> getPSNR(const QImage &a,const QImage &b) {
00023 int width= a.width(), height= a.height();
00024 int x, y;
00025 QRgb *line1, *line2;
00026 long sum, sumR, sumG, sumB;
00027 sum= sumR= sumG= sumB= 0;
00028 for (y=0; y<height; ++y) {
00029 line1= (QRgb*)a.scanLine(y);
00030 line2= (QRgb*)b.scanLine(y);
00031 for (x=0; x<width; ++x) {
00032 sum+= sqr( getGray(line1[x]) - getGray(line2[x]) );
00033 sumR+= sqr( qRed(line1[x]) - qRed(line2[x]) );
00034 sumG+= sqr( qGreen(line1[x]) - qGreen(line2[x]) );
00035 sumB+= sqr( qBlue(line1[x]) - qBlue(line2[x]) );
00036 }
00037 }
00038 vector<Real> result(4);
00039 result[0]= sumR;
00040 result[1]= sumG;
00041 result[2]= sumB;
00042 result[3]= sum;
00043 Real mul= Real(width*height) * Real(sqr(255));
00044 for (vector<Real>::iterator it=result.begin(); it!=result.end(); ++it)
00045 *it= Real(10) * log10(mul / *it);
00046 return result;
00047 }
00048
00049 }