Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncAnalyze.h


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4747#include <assert.h>
    4848#include "TLibCommon/CommonDef.h"
     49#include "TLibCommon/TComChromaFormat.h"
     50#include "math.h"
    4951
    5052//! \ingroup TLibEncoder
     
    5961{
    6062private:
    61   Double    m_dPSNRSumY;
    62   Double    m_dPSNRSumU;
    63   Double    m_dPSNRSumV;
     63  Double    m_dPSNRSum[MAX_NUM_COMPONENT];
    6464  Double    m_dAddBits;
    6565  UInt      m_uiNumPic;
    6666  Double    m_dFrmRate; //--CFG_KDY
    67  
     67  Double    m_MSEyuvframe[MAX_NUM_COMPONENT]; // sum of MSEs
     68
    6869public:
    69   TEncAnalyze() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
    7070  virtual ~TEncAnalyze()  {}
    71  
    72   Void  addResult( Double psnrY, Double psnrU, Double psnrV, Double bits)
    73   {
    74     m_dPSNRSumY += psnrY;
    75     m_dPSNRSumU += psnrU;
    76     m_dPSNRSumV += psnrV;
     71  TEncAnalyze() { clear(); }
     72
     73  Void  addResult( Double psnr[MAX_NUM_COMPONENT], Double bits, const Double MSEyuvframe[MAX_NUM_COMPONENT])
     74  {
    7775    m_dAddBits  += bits;
    78    
     76    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
     77    {
     78      m_dPSNRSum[i] += psnr[i];
     79      m_MSEyuvframe[i] += MSEyuvframe[i];
     80    }
     81
    7982    m_uiNumPic++;
    8083  }
    81  
    82   Double  getPsnrY()  { return  m_dPSNRSumY;  }
    83   Double  getPsnrU()  { return  m_dPSNRSumU;  }
    84   Double  getPsnrV()  { return  m_dPSNRSumV;  }
    85   Double  getBits()   { return  m_dAddBits;   }
    86   UInt    getNumPic() { return  m_uiNumPic;   }
    87  
     84
     85  Double  getPsnr(ComponentID compID) const { return  m_dPSNRSum[compID];  }
     86  Double  getBits()                   const { return  m_dAddBits;   }
     87  Void    setBits(Double numBits)     { m_dAddBits=numBits; }
     88  UInt    getNumPic()                 const { return  m_uiNumPic;   }
     89
    8890  Void    setFrmRate  (Double dFrameRate) { m_dFrmRate = dFrameRate; } //--CFG_KDY
    89   Void    clear() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
    90   Void    printOut ( Char cDelim )
     91  Void    clear()
     92  {
     93    m_dAddBits = 0;
     94    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
     95    {
     96      m_dPSNRSum[i] = 0;
     97      m_MSEyuvframe[i] = 0;
     98    }
     99    m_uiNumPic = 0;
     100  }
     101
     102
     103  Void calculateCombinedValues(const ChromaFormat chFmt, Double &PSNRyuv, Double &MSEyuv, const BitDepths &bitDepths)
     104  {
     105    MSEyuv    = 0;
     106    Int scale = 0;
     107
     108    Int maximumBitDepth = bitDepths.recon[CHANNEL_TYPE_LUMA];
     109    for (UInt channelTypeIndex = 1; channelTypeIndex < MAX_NUM_CHANNEL_TYPE; channelTypeIndex++)
     110    {
     111      if (bitDepths.recon[channelTypeIndex] > maximumBitDepth)
     112      {
     113        maximumBitDepth = bitDepths.recon[channelTypeIndex];
     114      }
     115    }
     116
     117    const UInt maxval                = 255 << (maximumBitDepth - 8);
     118    const UInt numberValidComponents = getNumberValidComponents(chFmt);
     119
     120    for (UInt comp=0; comp<numberValidComponents; comp++)
     121    {
     122      const ComponentID compID        = ComponentID(comp);
     123      const UInt        csx           = getComponentScaleX(compID, chFmt);
     124      const UInt        csy           = getComponentScaleY(compID, chFmt);
     125      const Int         scaleChan     = (4>>(csx+csy));
     126      const UInt        bitDepthShift = 2 * (maximumBitDepth - bitDepths.recon[toChannelType(compID)]); //*2 because this is a squared number
     127
     128      const Double      channelMSE    = (m_MSEyuvframe[compID] * Double(1 << bitDepthShift)) / Double(getNumPic());
     129
     130      scale  += scaleChan;
     131      MSEyuv += scaleChan * channelMSE;
     132    }
     133
     134    MSEyuv /= Double(scale);  // i.e. divide by 6 for 4:2:0, 8 for 4:2:2 etc.
     135    PSNRyuv = (MSEyuv==0 ? 999.99 : 10*log10((maxval*maxval)/MSEyuv));
     136  }
     137
     138
     139  Void    printOut ( Char cDelim, const ChromaFormat chFmt, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths )
    91140  {
    92141    Double dFps     =   m_dFrmRate; //--CFG_KDY
    93142    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
    94    
    95     printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
    96     //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
    97     printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
    98            getNumPic(), cDelim,
    99            getBits() * dScale,
    100            getPsnrY() / (Double)getNumPic(),
    101            getPsnrU() / (Double)getNumPic(),
    102            getPsnrV() / (Double)getNumPic() );
    103   }
    104  
    105   Void    printSummaryOut ()
    106   {
    107     FILE* pFile = fopen ("summaryTotal.txt", "at");
     143
     144    Double MSEBasedSNR[MAX_NUM_COMPONENT];
     145    if (printMSEBasedSNR)
     146    {
     147      for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
     148      {
     149        const ComponentID compID = ComponentID(componentIndex);
     150
     151        if (getNumPic() == 0)
     152        {
     153          MSEBasedSNR[compID] = 0 * dScale; // this is the same calculation that will be evaluated for any other statistic when there are no frames (it should result in NaN). We use it here so all the output is consistent.
     154        }
     155        else
     156        {
     157          //NOTE: this is not the true maximum value for any bitDepth other than 8. It comes from the original HM PSNR calculation
     158          const UInt maxval = 255 << (bitDepths.recon[toChannelType(compID)] - 8);
     159          const Double MSE = m_MSEyuvframe[compID];
     160
     161          MSEBasedSNR[compID] = (MSE == 0) ? 999.99 : (10 * log10((maxval * maxval) / (MSE / (Double)getNumPic())));
     162        }
     163      }
     164    }
     165
     166    switch (chFmt)
     167    {
     168      case CHROMA_400:
     169        if (printMSEBasedSNR)
     170        {
     171          printf( "         \tTotal Frames |   "   "Bitrate     "  "Y-PSNR" );
     172
     173          if (printSequenceMSE)
     174          {
     175            printf( "    Y-MSE\n" );
     176          }
     177          else
     178          {
     179            printf("\n");
     180          }
     181
     182          //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     183          printf( "Average: \t %8d    %c "          "%12.4lf  "    "%8.4lf",
     184                 getNumPic(), cDelim,
     185                 getBits() * dScale,
     186                 getPsnr(COMPONENT_Y) / (Double)getNumPic() );
     187
     188          if (printSequenceMSE)
     189          {
     190            printf( "  %8.4lf\n", m_MSEyuvframe[COMPONENT_Y ] / (Double)getNumPic() );
     191          }
     192          else
     193          {
     194            printf("\n");
     195          }
     196
     197          printf( "From MSE:\t %8d    %c "          "%12.4lf  "    "%8.4lf\n",
     198                 getNumPic(), cDelim,
     199                 getBits() * dScale,
     200                 MSEBasedSNR[COMPONENT_Y] );
     201        }
     202        else
     203        {
     204          printf( "\tTotal Frames |   "   "Bitrate     "  "Y-PSNR" );
     205
     206          if (printSequenceMSE)
     207          {
     208            printf( "    Y-MSE\n" );
     209          }
     210          else
     211          {
     212            printf("\n");
     213          }
     214
     215          //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     216          printf( "\t %8d    %c "          "%12.4lf  "    "%8.4lf",
     217                 getNumPic(), cDelim,
     218                 getBits() * dScale,
     219                 getPsnr(COMPONENT_Y) / (Double)getNumPic() );
     220
     221          if (printSequenceMSE)
     222          {
     223            printf( "  %8.4lf\n", m_MSEyuvframe[COMPONENT_Y ] / (Double)getNumPic() );
     224          }
     225          else
     226          {
     227            printf("\n");
     228          }
     229        }
     230        break;
     231      case CHROMA_420:
     232      case CHROMA_422:
     233      case CHROMA_444:
     234        {
     235          Double PSNRyuv = MAX_DOUBLE;
     236          Double MSEyuv  = MAX_DOUBLE;
     237         
     238          calculateCombinedValues(chFmt, PSNRyuv, MSEyuv, bitDepths);
     239
     240          if (printMSEBasedSNR)
     241          {
     242            printf( "         \tTotal Frames |   "   "Bitrate     "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR    "  "YUV-PSNR " );
     243
     244            if (printSequenceMSE)
     245            {
     246              printf( " Y-MSE     "  "U-MSE     "  "V-MSE    "  "YUV-MSE \n" );
     247            }
     248            else
     249            {
     250              printf("\n");
     251            }
     252
     253            //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     254            printf( "Average: \t %8d    %c "          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf  "   "%8.4lf",
     255                   getNumPic(), cDelim,
     256                   getBits() * dScale,
     257                   getPsnr(COMPONENT_Y) / (Double)getNumPic(),
     258                   getPsnr(COMPONENT_Cb) / (Double)getNumPic(),
     259                   getPsnr(COMPONENT_Cr) / (Double)getNumPic(),
     260                   PSNRyuv );
     261
     262            if (printSequenceMSE)
     263            {
     264              printf( "  %8.4lf  "   "%8.4lf  "    "%8.4lf  "   "%8.4lf\n",
     265                     m_MSEyuvframe[COMPONENT_Y ] / (Double)getNumPic(),
     266                     m_MSEyuvframe[COMPONENT_Cb] / (Double)getNumPic(),
     267                     m_MSEyuvframe[COMPONENT_Cr] / (Double)getNumPic(),
     268                     MSEyuv );
     269            }
     270            else
     271            {
     272              printf("\n");
     273            }
     274
     275            printf( "From MSE:\t %8d    %c "          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf  "   "%8.4lf\n",
     276                   getNumPic(), cDelim,
     277                   getBits() * dScale,
     278                   MSEBasedSNR[COMPONENT_Y],
     279                   MSEBasedSNR[COMPONENT_Cb],
     280                   MSEBasedSNR[COMPONENT_Cr],
     281                   PSNRyuv );
     282          }
     283          else
     284          {
     285            printf( "\tTotal Frames |   "   "Bitrate     "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR    "  "YUV-PSNR " );
     286           
     287            if (printSequenceMSE)
     288            {
     289              printf( " Y-MSE     "  "U-MSE     "  "V-MSE    "  "YUV-MSE \n" );
     290            }
     291            else
     292            {
     293              printf("\n");
     294            }
     295
     296            //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     297            printf( "\t %8d    %c "          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf  "   "%8.4lf",
     298                   getNumPic(), cDelim,
     299                   getBits() * dScale,
     300                   getPsnr(COMPONENT_Y) / (Double)getNumPic(),
     301                   getPsnr(COMPONENT_Cb) / (Double)getNumPic(),
     302                   getPsnr(COMPONENT_Cr) / (Double)getNumPic(),
     303                   PSNRyuv );
     304
     305            if (printSequenceMSE)
     306            {
     307              printf( "  %8.4lf  "   "%8.4lf  "    "%8.4lf  "   "%8.4lf\n",
     308                     m_MSEyuvframe[COMPONENT_Y ] / (Double)getNumPic(),
     309                     m_MSEyuvframe[COMPONENT_Cb] / (Double)getNumPic(),
     310                     m_MSEyuvframe[COMPONENT_Cr] / (Double)getNumPic(),
     311                     MSEyuv );
     312            }
     313            else
     314            {
     315              printf("\n");
     316            }
     317          }
     318        }
     319        break;
     320      default:
     321        fprintf(stderr, "Unknown format during print out\n");
     322        exit(1);
     323        break;
     324    }
     325  }
     326
     327
     328  Void    printSummary(const ChromaFormat chFmt, const Bool printSequenceMSE, const BitDepths &bitDepths, const std::string &sFilename)
     329  {
     330    FILE* pFile = fopen (sFilename.c_str(), "at");
     331
    108332    Double dFps     =   m_dFrmRate; //--CFG_KDY
    109333    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
    110    
    111     fprintf(pFile, "%f\t %f\t %f\t %f\n", getBits() * dScale,
    112             getPsnrY() / (Double)getNumPic(),
    113             getPsnrU() / (Double)getNumPic(),
    114             getPsnrV() / (Double)getNumPic() );
     334    switch (chFmt)
     335    {
     336      case CHROMA_400:
     337        fprintf(pFile, "%f\t %f\n",
     338            getBits() * dScale,
     339            getPsnr(COMPONENT_Y) / (Double)getNumPic() );
     340        break;
     341      case CHROMA_420:
     342      case CHROMA_422:
     343      case CHROMA_444:
     344        {
     345          Double PSNRyuv = MAX_DOUBLE;
     346          Double MSEyuv  = MAX_DOUBLE;
     347         
     348          calculateCombinedValues(chFmt, PSNRyuv, MSEyuv, bitDepths);
     349
     350          fprintf(pFile, "%f\t %f\t %f\t %f\t %f",
     351              getBits() * dScale,
     352              getPsnr(COMPONENT_Y) / (Double)getNumPic(),
     353              getPsnr(COMPONENT_Cb) / (Double)getNumPic(),
     354              getPsnr(COMPONENT_Cr) / (Double)getNumPic(),
     355              PSNRyuv );
     356
     357          if (printSequenceMSE)
     358          {
     359            fprintf(pFile, "\t %f\t %f\t %f\t %f\n",
     360                m_MSEyuvframe[COMPONENT_Y ] / (Double)getNumPic(),
     361                m_MSEyuvframe[COMPONENT_Cb] / (Double)getNumPic(),
     362                m_MSEyuvframe[COMPONENT_Cr] / (Double)getNumPic(),
     363                MSEyuv );
     364          }
     365          else
     366          {
     367            fprintf(pFile, "\n");
     368          }
     369
     370          break;
     371        }
     372
     373      default:
     374          fprintf(stderr, "Unknown format during print out\n");
     375          exit(1);
     376          break;
     377    }
     378
    115379    fclose(pFile);
    116380  }
    117  
    118   Void    printOutInterlaced ( Char cDelim, Double bits )
    119   {
    120     Double dFps     =   m_dFrmRate; //--CFG_KDY
    121     Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
    122    
    123     printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
    124     //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
    125     printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
    126            getNumPic(), cDelim,
    127            bits * dScale,
    128            getPsnrY() / (Double)getNumPic(),
    129            getPsnrU() / (Double)getNumPic(),
    130            getPsnrV() / (Double)getNumPic() );
    131   }
    132  
    133   Void    printSummaryOutInterlaced (Int bits)
    134   {
    135     FILE* pFile = fopen ("summaryTotal.txt", "at");
    136     Double dFps     =   m_dFrmRate; //--CFG_KDY
    137     Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
    138    
    139     fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
    140             getPsnrY() / (Double)getNumPic(),
    141             getPsnrU() / (Double)getNumPic(),
    142             getPsnrV() / (Double)getNumPic() );
    143     fclose(pFile);
    144   }
    145  
    146  
    147   Void    printSummary(Char ch)
    148   {
    149     FILE* pFile = NULL;
    150    
    151     switch( ch )
    152     {
    153       case 'I':
    154         pFile = fopen ("summary_I.txt", "at");
    155         break;
    156       case 'P':
    157         pFile = fopen ("summary_P.txt", "at");
    158         break;
    159       case 'B':
    160         pFile = fopen ("summary_B.txt", "at");
    161         break;
    162       default:
    163         assert(0);
    164         return;
    165         break;
    166     }
    167    
    168     Double dFps     =   m_dFrmRate; //--CFG_KDY
    169     Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
    170    
    171     fprintf(pFile, "%f\t %f\t %f\t %f\n",
    172             getBits() * dScale,
    173             getPsnrY() / (Double)getNumPic(),
    174             getPsnrU() / (Double)getNumPic(),
    175             getPsnrV() / (Double)getNumPic() );
    176    
    177     fclose(pFile);
    178   }
    179381};
    180382
    181 #if !H_MV
    182383extern TEncAnalyze             m_gcAnalyzeAll;
    183384extern TEncAnalyze             m_gcAnalyzeI;
     
    186387
    187388extern TEncAnalyze             m_gcAnalyzeAll_in;
    188 #endif
    189389
    190390//! \}
Note: See TracChangeset for help on using the changeset viewer.