码迷,mamicode.com
首页 > 其他好文 > 详细

Image quality evaluation

时间:2017-03-25 20:00:04      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:char   struct   cti   use   general   mat   turn   double   har   

Generally,we use PSNR and SSIM to judge the quality of a given photo,or to select a useful denoising algorithm.

I.PSNR(peak signal to noise ratio)

double PSNR(const Mat&I, const Mat&K)
{
int w = I.size().width;
int h = I.size().height;

double MSE = 0.0;
for (int i = 0; i<w; ++i)
for (int j = 0; j<h; ++j)
MSE += (I.at<uchar>(j, i) - K.at<uchar>(j, i))*(I.at<uchar>(j, i) - K.at<uchar>(j, i));
MSE /= (w*h);

double psnr = 10 * log10(255 * 255 / MSE);

return psnr;
}

II.SSIM(structural similarity)

double SSIM(const Mat& x, const Mat& y) {
double meanX = pictureMean(x);
double meanY = pictureMean(y);
double sigmaX = pictureSigma(x,meanX);
double sigmaY = pictureSigma(y, meanY);
double sigmaXY = pictureCovSigma(x,y,meanX,meanY);

double k1 = 0.01;
double k2 = 0.03;
double L = 255;
double C1 = (k1*L)*(k1*L);
double C2 = (k2*L)*(k2*L);
double C3 = C2 / 2;

double l = (2*meanX*meanY+C1) / (meanX*meanX+meanY*meanY+C1);
double c = (2*sigmaX*sigmaY) / (sigmaX*sigmaX+sigmaY*sigmaY+C2);
double s = (sigmaXY+C3) / (sigmaX*sigmaY+C3);

double ssim = l*c*s;

return ssim;
}

assistant functions:

double pictureMean(const Mat& in) {
int w = in.size().width;
int h = in.size().height;

double mean = 0.0;
for (int i = 0; i<w; ++i)
for (int j = 0; j<h; ++j)
mean += (double)in.at<uchar>(j, i);
mean =mean/(double)(w*h);

return mean;
}

double pictureSigma(const Mat& in, double mean) {
int w = in.size().width;
int h = in.size().height;

double sigma = 0.0;
for (int i = 0; i<w; ++i)
for (int j = 0; j<h; ++j)
sigma += ((double)in.at<uchar>(j, i)-mean)*((double)in.at<uchar>(j, i) - mean);
sigma = sigma / (double)(w*h-1);
sigma = sqrt(sigma);

return sigma;
}

double pictureCovSigma(const Mat& x, const Mat& y, double meanX, double meanY) {
int w = x.size().width;
int h = x.size().height;

double sigma = 0.0;
for (int i = 0; i<w; ++i)
for (int j = 0; j<h; ++j)
sigma += ((double)x.at<uchar>(j, i) - meanX)*((double)y.at<uchar>(j, i) - meanY);
sigma = sigma / (double)(w*h - 1);

return sigma;
}

 

Image quality evaluation

标签:char   struct   cti   use   general   mat   turn   double   har   

原文地址:http://www.cnblogs.com/ssMellon/p/6618100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!