PICCANTE  0.4
The hottest HDR imaging library!
m_psnr.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_METRICS_M_PSNR_HPP
19 #define PIC_METRICS_M_PSNR_HPP
20 
21 #include <math.h>
22 
23 #include "../base.hpp"
24 
25 #include "../util/array.hpp"
26 
27 #include "../image.hpp"
28 #include "../tone_mapping/get_all_exposures.hpp"
29 #include "../metrics/base.hpp"
30 #include "../metrics/mse.hpp"
31 
32 namespace pic {
33 
35 
45 PIC_INLINE double mPSNR(Image *ori, Image *cmp, MULTI_EXPOSURE_TYPE type, int minFstop = 0, int maxFstop = 0)
46 {
47  if(ori == NULL || cmp == NULL) {
48  return -2.0;
49  }
50 
51  if(!ori->isValid() || !cmp->isValid()) {
52  return -3.0;
53  }
54 
55  if(!ori->isSimilarType(cmp)) {
56  return -1.0;
57  }
58 
59  std::vector<float> exposures;
60 
61  switch (type) {
62  case MET_HISTOGRAM: {
63  exposures = getAllExposures(ori);
64  } break;
65 
66  case MET_MIN_MAX: {
67  if(minFstop == maxFstop) {
68  getMinMaxFstops(ori, minFstop, maxFstop);
69  }
70 
71  int nExposures_v = 0;
72  float *exposures_v = NULL;
73  Arrayf::genRange(float(minFstop), 1.0f, float(maxFstop), exposures_v, nExposures_v);
74 
75  exposures.insert(exposures.begin(), exposures_v, exposures_v + nExposures_v);
76 
77  } break;
78 
79  case MET_FROM_INPUT: {
80  for(int i = minFstop; i <= maxFstop; i++) {
81  exposures.push_back(float(i));
82  }
83 
84  } break;
85  }
86 
87  if(exposures.empty()) {
88  return -5.0;
89  }
90 
91  #ifdef PIC_DEBUG
92  printf("-------------------------------------------------------\n");
93  printf("-- mPSNR:\n");
94  printf("-- min F-stop: %d \t max F-stop: %d\n", minFstop, maxFstop);
95  #endif
96 
97  int nBit = 8;
98  float gamma = 2.2f; //typically 2.2
99  auto n = exposures.size();
100  double mse = 0.0;
101  for(auto i = 0; i < n; i++) {
102  double mse_i = MSE(ori, cmp, gamma, exposures[i], nBit);
103 
104  #ifdef PIC_DEBUG
105  printf("-- Pass: %d \t MSE: %g\n", i, mse_i);
106  #endif
107 
108  mse += mse_i;
109  }
110 
111  mse /= double(n * ori->channels);
112 
113  int nValues = (1 << nBit) - 1;
114  double nValuesd = double(nValues);
115  double ret = 10.0 * log10((nValuesd * nValuesd) / mse);
116 
117  #ifdef PIC_DEBUG
118  printf("-- value: %f\n", ret);
119  printf("-------------------------------------------------------");
120  #endif
121 
122  return ret;
123 }
124 
125 } // end namespace pic
126 
127 #endif /* PIC_METRICS_M_PSNR_HPP */
128 
static T * genRange(T minVal, T step, T maxVal, T *ret, int &n)
genRange
Definition: array.hpp:156
int channels
Definition: image.hpp:80
PIC_INLINE double mPSNR(Image *ori, Image *cmp, MULTI_EXPOSURE_TYPE type, int minFstop=0, int maxFstop=0)
mPSNR computes the multiple-exposure peak signal-to-noise ratio (mPSNR) between two images...
Definition: m_psnr.hpp:45
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
Definition: m_psnr.hpp:34
PIC_INLINE void getMinMaxFstops(Image *imgIn, int &minFstop, int &maxFstop)
getMinMaxFstops computes the minimum and maximum f-stop values of an image.
Definition: get_all_exposures.hpp:39
PIC_INLINE double MSE(Image *ori, Image *cmp, bool bLargeDifferences=false, METRICS_DOMAIN type=MD_LIN)
MSE computes the mean square error (MSE) between two images.
Definition: mse.hpp:37
PIC_INLINE std::vector< float > getAllExposures(Image *imgIn)
getAllExposures computes all required exposure values for reconstructing the input image using histog...
Definition: get_all_exposures.hpp:107
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
MULTI_EXPOSURE_TYPE
Definition: m_psnr.hpp:34
Definition: m_psnr.hpp:34
Definition: m_psnr.hpp:34