全參考視頻質量評價方法
常用的方法有兩種
1.PSNR(Peak Signal to Noise Ratio)峰值信噪比:一種評價圖像的客觀標準膝迎。
2.SSIM(structural similarity index)霉晕,結構相似性驶拱,是一種衡量兩幅圖像相似度的指標梯皿。SSIM使用的兩張圖像中揣云,一張為未經壓縮的無失真圖像妆绞,另一張為失真后的圖像板惑。
PSNR_ C語言實現(xiàn):
void PSNR_compute()
{
int width = //寬;
int height = //高;
uint8_t* p = (uint8_t*)malloc(width*height*3/2);
if (p == NULL) {
return;
}
size_t toread = width*height*3/2;
if (fread(p,1,toread,reference_file) != toread) {
free(p);
return;
}
const uint8_t* yptr = //y分量;
const uint8_t* cbptr = //cb分量;
const uint8_t* crptr = //cr分量;
int stride = Y的stride.
int cstride = U或者V的Stride;
double img_mse_y = MSE( yptr, stride, p, width, width, height);
double img_mse_cb = MSE(cbptr, cstride, p+width*height, width/2, width/2,height/2);
double img_mse_cr = MSE(crptr, cstride, p+width*height*5/4, width/2, width/2,height/2);
mse_frames++;
mse_y += img_mse_y;
mse_cb += img_mse_cb;
mse_cr += img_mse_cr;
printf("%5d %6f %6f %6f %6f\n",
framecnt,
PSNR(img_mse_y), PSNR(img_mse_cb), PSNR(img_mse_cr),
ssimSum);
free(p);
}
double MSE(const uint8_t* img, int imgStride,
const uint8_t* ref, int refStride,
int width, int height)
{
double sum=0.0;
const uint8_t* iPtr = img;
const uint8_t* rPtr = ref;
for (int y=0;y<height;y++) {
uint32_t lineSum=0;
for (int x=0;x<width;x++) {
int diff = iPtr[x] - rPtr[x];
lineSum += diff*diff;
}
sum += ((double)lineSum)/width;
iPtr += imgStride;
rPtr += refStride;
}
return sum/height;
}
double PSNR(double mse)
{
if (mse==0) { return 99.99999; }
return 10*log10(255.0*255.0/mse);
}
void main () {
while () {
//計算所有裆熙。
PSNR_compute()
}
//最終結果
printf("#total %6f %6f %6f %6f\n",
PSNR(mse_y /mse_frames),
PSNR(mse_cb/mse_frames),
PSNR(mse_cr/mse_frames),
ssim_y/ssim_frames);
}