PICCANTE  0.4
The hottest HDR imaging library!
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_PSNR_HPP
19 #define PIC_METRICS_PSNR_HPP
20 
21 #include <math.h>
22 
23 #include "../base.hpp"
24 #include "../image.hpp"
25 #include "../util/array.hpp"
26 #include "../metrics/base.hpp"
27 #include "../metrics/mse.hpp"
28 
29 namespace pic {
30 
41 PIC_INLINE double PSNR(Image *ori, Image *cmp, double max_value = -1.0, bool bLargeDifferences = false, METRICS_DOMAIN type = MD_LIN)
42 {
43  if(ori == NULL || cmp == NULL) {
44  return -2.0;
45  }
46 
47  if(!ori->isValid() || !cmp->isValid()) {
48  return -4.0;
49  }
50 
51  if(!ori->isSimilarType(cmp)) {
52  return -1.0;
53  }
54 
55  if(max_value <= 0.0) {
56  float *max_value_ori = ori->getMaxVal(NULL, NULL);
57  float *max_value_cmp = cmp->getMaxVal(NULL, NULL);
58 
59  int ind;
60  float m_ori = Arrayf::getMax(max_value_ori, ori->channels, ind);
61  float m_cmp = Arrayf::getMax(max_value_cmp, cmp->channels, ind);
62 
63  max_value = double(MAX(m_ori, m_cmp));
64 
65  delete[] max_value_ori;
66  delete[] max_value_cmp;
67  }
68 
69  double rmse_value = RMSE(ori, cmp, bLargeDifferences, type);
70 
71  max_value = double(changeDomain(float(max_value), type));
72 
73  if(rmse_value > 0.0) {
74  return 20.0 * log10(max_value / rmse_value);
75  } else {
76  return -3.0;
77  }
78 }
79 
80 } // end namespace pic
81 
82 #endif /* PIC_METRICS_PSNR_HPP */
83 
static T getMax(T *data, int size, int &ind)
getMax
Definition: array.hpp:516
int channels
Definition: image.hpp:80
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
float changeDomain(float x, METRICS_DOMAIN type=MD_LIN)
changeDomain
Definition: base.hpp:38
PIC_INLINE double RMSE(Image *ori, Image *cmp, bool bLargeDifferences=false, METRICS_DOMAIN type=MD_LIN)
RMSE computes the root mean squared error (RMSE) between two images.
Definition: mse.hpp:135
#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...
#define MAX(a, b)
Definition: math.hpp:73
METRICS_DOMAIN
Definition: base.hpp:30
PIC_INLINE double PSNR(Image *ori, Image *cmp, double max_value=-1.0, bool bLargeDifferences=false, METRICS_DOMAIN type=MD_LIN)
PSNR computes the peak signal to noise ratio (PSNR) between two images.
Definition: psnr.hpp:41
float * getMaxVal(BBox *box, float *ret)
getMaxVal computes the maximum value for the current Image.
Definition: base.hpp:30