img_dist_snr.c
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:2k
源码类别:

Audio

开发平台:

Visual C++

  1. /*!
  2.  *************************************************************************************
  3.  * file img_dist_snr.c
  4.  *
  5.  * brief
  6.  *    Compute signal to noise ratio (SNR) between the encoded image and the reference image
  7.  *
  8.  * author
  9.  *    Main contributors (see contributors.h for copyright, address and affiliation details)
  10.  *     - Woo-Shik Kim                    <wooshik.kim@usc.edu>
  11.  *     - Alexis Michael Tourapis         <alexismt@ieee.org>
  12.  *************************************************************************************
  13.  */
  14. #include "contributors.h"
  15. #include <math.h>
  16. #include "global.h"
  17. #include "img_distortion.h"
  18. #include "enc_statistics.h"
  19. /*!
  20.  ************************************************************************
  21.  * brief
  22.  *    Find SNR for all three components
  23.  ************************************************************************
  24.  */
  25. void find_snr(ImageStructure *imgREF, ImageStructure *imgSRC, DistMetric *metricSSE, DistMetric *metricPSNR)
  26. {
  27.   FrameFormat *format = &imgREF->format;
  28.   // Luma.
  29.   metricSSE ->value[0] = (float) compute_SSE(imgREF->data[0], imgSRC->data[0], 0, 0, format->height, format->width);
  30.   metricPSNR->value[0] = psnr(format->max_value_sq[0], format->size_cmp[0], metricSSE->value[0]);
  31.   // Chroma.
  32.   if (format->yuv_format != YUV400)
  33.   {   
  34.     metricSSE ->value[1] = (float) compute_SSE(imgREF->data[1], imgSRC->data[1], 0, 0, format->height_cr, format->width_cr);
  35.     metricPSNR->value[1] = psnr(format->max_value_sq[1], format->size_cmp[1], metricSSE->value[1]);
  36.     metricSSE ->value[2] = (float) compute_SSE(imgREF->data[2], imgSRC->data[2], 0, 0, format->height_cr, format->width_cr);
  37.     metricPSNR->value[2] = psnr(format->max_value_sq[2], format->size_cmp[2], metricSSE->value[2]);
  38.   }
  39.    
  40.   {
  41.     accumulate_average(metricSSE,  dist->frame_ctr);
  42.     accumulate_average(metricPSNR, dist->frame_ctr);
  43.     accumulate_avslice(metricSSE,  img->type, stats->frame_ctr[img->type]);
  44.     accumulate_avslice(metricPSNR, img->type, stats->frame_ctr[img->type]);
  45.   }
  46. }