From f502dcc70a04deb92aa273d8bbd2eb1f377b6c25 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 3 Apr 2019 23:37:16 +0100 Subject: [PATCH] Add support for WS-PSNR quality metric --- app/docks/QualityMeasurementSidebar.cpp | 3 +++ lib/CalypFrame.cpp | 35 +++++++++++++++++++++++-- lib/CalypFrame.h | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/docks/QualityMeasurementSidebar.cpp b/app/docks/QualityMeasurementSidebar.cpp index d413594..f309887 100644 --- a/app/docks/QualityMeasurementSidebar.cpp +++ b/app/docks/QualityMeasurementSidebar.cpp @@ -185,6 +185,8 @@ void QualityMeasurementSidebar::updateSidebarData() VideoSubWindow* refSubWindow = m_pcCurrentVideoSubWindow->getRefSubWindow(); if( refSubWindow ) { + QApplication::setOverrideCursor( Qt::WaitCursor ); + CalypFrame* currFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); CalypFrame* refFrame = refSubWindow->getCurrFrame(); double quality; @@ -199,6 +201,7 @@ void QualityMeasurementSidebar::updateSidebarData() { m_ppcLabelQualityValue[component]->setText( zeroValue ); } + QApplication::restoreOverrideCursor(); return; } else diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index e05a4f6..39acabf 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -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 CalypFrame::supportedQualityMetricsList() "PSNR", "MSE", "SSIM", + "WS-PSNR", }; } @@ -1262,6 +1262,7 @@ std::vector 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 ); +} diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index d8f1327..ae3657f 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -364,6 +364,7 @@ public: PSNR_METRIC = 0, MSE_METRIC, SSIM_METRIC, + WSPSNR_METRIC, NUMBER_METRICS, }; @@ -373,7 +374,7 @@ public: double getMSE( CalypFrame* Org, unsigned int component ); double getPSNR( CalypFrame* Org, unsigned int component ); double getSSIM( CalypFrame* Org, unsigned int component ); - + double getWSPNR( CalypFrame* Org, unsigned int component ); /** @} */ private: