Add support for WS-PSNR quality metric

This commit is contained in:
2019-04-03 23:37:16 +01:00
parent cf2109e016
commit f502dcc70a
3 changed files with 38 additions and 3 deletions
+33 -2
View File
@@ -1194,7 +1194,7 @@ bool CalypFrame::fromMat( cv::Mat& cvMat, int channel )
else
channel = 0;
if( cvMat.channels() != numChannels )
if( cvMat.channels() != int( numChannels ) )
{
return false;
}
@@ -1205,7 +1205,6 @@ bool CalypFrame::fromMat( cv::Mat& cvMat, int channel )
cv::Mat tmpMat( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) );
if( numChannels > 0 )
{
unsigned color_space = getColorSpace();
switch( getColorSpace() )
{
case CLP_COLOR_YUV:
@@ -1253,6 +1252,7 @@ std::vector<ClpString> CalypFrame::supportedQualityMetricsList()
"PSNR",
"MSE",
"SSIM",
"WS-PSNR",
};
}
@@ -1262,6 +1262,7 @@ std::vector<ClpString> CalypFrame::supportedQualityMetricsUnitsList()
"dB",
"",
"",
"dB",
};
}
@@ -1282,6 +1283,9 @@ double CalypFrame::getQuality( int Metric, CalypFrame* Org, unsigned int compone
case SSIM_METRIC:
return getSSIM( Org, component );
break;
case WSPSNR_METRIC:
return getWSPNR( Org, component );
break;
default:
assert( 0 );
};
@@ -1414,3 +1418,30 @@ double CalypFrame::getSSIM( CalypFrame* Org, unsigned int component )
}
return dSSIM;
}
double CalypFrame::getWSPNR( CalypFrame* Org, unsigned int component )
{
ClpPel* pPelYUV = getPelBufferYUV()[component][0];
ClpPel* pOrgPelYUV = Org->getPelBufferYUV()[component][0];
unsigned height = getHeight( component );
unsigned width = getWidth( component );
double ssd = 0;
double weight_sum = 0;
for( unsigned y = 0; y < height; y++ )
for( unsigned x = 0; x < width; x++ )
{
int diff = ( *pPelYUV++ ) - ( *pOrgPelYUV++ );
double weight = cos( ( y + 0.5 - height / 2 ) * 3.1415926 / height );
ssd += (double)( diff * diff ) * weight * 100000;
weight_sum += weight;
}
if( ssd == 0.0 )
{
return 100.00;
}
unsigned long uiMaxValue = ( 1 << Org->getBitsPel() ) - 1;
return 10 * log10( double( uiMaxValue * uiMaxValue ) * weight_sum / ssd / 100000 );
}