Image quality evaluation
Posted 空山皓月
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Image quality evaluation相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Paper | Making a "Completely Blind" Image Quality Analyzer
Offloading Monocular Visual Odometry with Edge Computing: Optimizing Image Quality in Multi-Robot Sy