【实验四】DPCM编码
一、实验原理
二、实验过程
//计算PSNR
void PrintPSNR(unsigned char* oriBuffer, unsigned char* recBuffer, int qBits, const char* psnrFileName) {
double mse;
double sum = 0;
double temp;
double psnr;
for (int i = 0; i < w * h; i++) {
temp = pow((float)(oriBuffer[i] - recBuffer[i]), 2);
sum += temp;
}
mse = sum / (w * h);
psnr = 10 * log10(255 * 255 / mse);
/* Output the stats into a csv file */
FILE* outFilePtr;
if (fopen_s(&outFilePtr, psnrFileName, "ab") == 0) {
cout << "Successfully opened \"" << psnrFileName << "\".\n";
} else {
cout << "WARNING!! Failed to open \"" << psnrFileName << "\".\n";
exit(-1);
}
fprintf(outFilePtr, "%d,%lf\n", qBits, psnr);
fclose(outFilePtr);
}