From 0e205c7a487607fb01288d75fd84733c783f13f2 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 29 Dec 2014 20:05:55 +0000 Subject: [PATCH] Change MeasurePSNR to LumaAverage --- modules/CMakeLists.txt | 2 +- modules/LumaAverage.cpp | 64 +++++++++++++++++ modules/{MeasurePSNR.h => LumaAverage.h} | 23 +++---- modules/MeasurePSNR.cpp | 87 ------------------------ modules/PlaYUVerModuleFactory.cpp | 1 + 5 files changed, 77 insertions(+), 100 deletions(-) create mode 100644 modules/LumaAverage.cpp rename modules/{MeasurePSNR.h => LumaAverage.h} (73%) delete mode 100644 modules/MeasurePSNR.cpp diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 493d340..fef8861 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -35,7 +35,7 @@ ADD_MODULE( FilterComponentChromaU "FilterComponent" ) ADD_MODULE( FilterComponentChromaV "FilterComponent" ) ADD_MODULE( FrameDifference "FrameDifference" ) ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) -#ADD_MODULE( MeasurePSNR "MeasurePSNR" ) +ADD_MODULE( LumaAverage "LumaAverage" ) IF( USE_OPENCV ) ADD_MODULE( DisparityStereoVar "DisparityStereoVar" ) ENDIF() diff --git a/modules/LumaAverage.cpp b/modules/LumaAverage.cpp new file mode 100644 index 0000000..2191f53 --- /dev/null +++ b/modules/LumaAverage.cpp @@ -0,0 +1,64 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file LumaAverage.cpp + * \brief Luma frame average + */ + +#include "LumaAverage.h" + +namespace plaYUVer +{ + +LumaAverage::LumaAverage() +{ + /* Module Definition */ + m_iModuleType = FRAME_MEASUREMENT_MODULE; + m_pchModuleCategory = "Measurements"; + m_pchModuleName = "Luma Average"; + m_pchModuleTooltip = "Measure the average of luma component"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_SIDEBAR; + m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; +} + +Void LumaAverage::create( PlaYUVerFrame* frame ) +{ +} + +Double LumaAverage::measure( PlaYUVerFrame* frame ) +{ + Double average = 0; + Pel* pPel = frame->getPelBufferYUV()[0][0]; + for( UInt y = 0; y < frame->getHeight(); y++ ) + for( UInt x = 0; x < frame->getWidth(); x++ ) + { + average += *pPel; + } + return average / Double( frame->getHeight() * frame->getWidth() ); +} + +Void LumaAverage::destroy() +{ + +} + +} // NAMESPACE + diff --git a/modules/MeasurePSNR.h b/modules/LumaAverage.h similarity index 73% rename from modules/MeasurePSNR.h rename to modules/LumaAverage.h index 7ec1f7e..d67c4ec 100644 --- a/modules/MeasurePSNR.h +++ b/modules/LumaAverage.h @@ -18,37 +18,36 @@ */ /** - * \file MeasurePSNR.h - * \brief Frame Difference module + * \file LumaAverage.h + * \brief Luma frame average */ -#ifndef __MEASUREPSNR_H__ -#define __MEASUREPSNR_H__ + +#ifndef __LUMAAVERAGE_H__ +#define __LUMAAVERAGE_H__ #include "PlaYUVerModuleIf.h" namespace plaYUVer { -class MeasurePSNR: public PlaYUVerModuleIf +class LumaAverage: public PlaYUVerModuleIf { - REGISTER_CLASS_FACTORY( MeasurePSNR ) + REGISTER_CLASS_FACTORY( LumaAverage ) private: public: - MeasurePSNR(); - virtual ~MeasurePSNR() + LumaAverage(); + virtual ~LumaAverage() { } Void create( PlaYUVerFrame* ); - Double measure( PlaYUVerFrame*, PlaYUVerFrame* ); + Double measure( PlaYUVerFrame* ); Void destroy(); - static Double getMSE( PlaYUVerFrame* Org, PlaYUVerFrame* Rec, Int component ); - }; } // NAMESPACE -#endif // __MEASUREPSNR_H__ +#endif // __LUMAAVERAGE_H__ diff --git a/modules/MeasurePSNR.cpp b/modules/MeasurePSNR.cpp deleted file mode 100644 index 583e614..0000000 --- a/modules/MeasurePSNR.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * \file MeasurePSNR.cpp - * \brief Frame Difference module - */ - -#include "MeasurePSNR.h" - -namespace plaYUVer -{ - -MeasurePSNR::MeasurePSNR() -{ - /* Module Definition */ - m_iModuleType = FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "Quality"; - m_pchModuleName = "PSNR Y"; - m_pchModuleTooltip = "Measure the PSNR between two images"; - m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; - m_uiModuleRequirements = MODULE_REQUIRES_SIDEBAR; - m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; -} - -Void MeasurePSNR::create( PlaYUVerFrame* Org ) -{ -} - -Double MeasurePSNR::getMSE( PlaYUVerFrame* Org, PlaYUVerFrame* Rec, Int component ) -{ - Pel* pInput1PelYUV = Org->getPelBufferYUV()[component][0]; - Pel* pInput2PelYUV = Rec->getPelBufferYUV()[component][0]; - - Int aux_pel_1, aux_pel_2; - Int diff = 0; - Double ssd = 0; - - for( UInt y = 0; y < Org->getHeight(); y++ ) - for( UInt x = 0; x < Org->getWidth(); x++ ) - { - aux_pel_1 = *pInput1PelYUV++; - aux_pel_2 = *pInput2PelYUV++; - diff = aux_pel_1 - aux_pel_2; - ssd += ( Double )( diff * diff ); - } - if( ssd == 0.0 ) - { - return 0.0; - } - return ssd / ( Org->getWidth() * Org->getHeight() ); -} - -Double MeasurePSNR::measure( PlaYUVerFrame* Org, PlaYUVerFrame* Rec ) -{ - Double psnrY = 100; - Double mseY = MeasurePSNR::getMSE( Org, Rec, LUMA ); - - if( mseY != 0 ) - psnrY = 10 * log10( 65025 / mseY ); - - return psnrY; -} - -Void MeasurePSNR::destroy() -{ - -} - -} // NAMESPACE - diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp index b50d1a9..0481b9a 100644 --- a/modules/PlaYUVerModuleFactory.cpp +++ b/modules/PlaYUVerModuleFactory.cpp @@ -37,6 +37,7 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "FilterComponentChromaV", &FilterComponentChromaV::Create ); Register( "FrameDifference", &FrameDifference::Create ); Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); + Register( "LumaAverage", &LumaAverage::Create ); Register( "DisparityStereoVar", &DisparityStereoVar::Create ); }