PICCANTE  0.4
The hottest HDR imaging library!
log_rmse.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_LOG_RMSE_HPP
19 #define PIC_METRICS_LOG_RMSE_HPP
20 
21 #include <math.h>
22 
23 #include "../base.hpp"
24 #include "../image.hpp"
25 #include "../util/math.hpp"
26 #include "../metrics/base.hpp"
27 
28 namespace pic {
29 
36 PIC_INLINE double logRMSE(Image *ori, Image *cmp)
37 {
38  if(ori == NULL || cmp == NULL) {
39  return -2.0;
40  }
41 
42  if(!ori->isValid() || !cmp->isValid()) {
43  return -4.0;
44  }
45 
46  if(!ori->isSimilarType(cmp)) {
47  return -1.0;
48  }
49 
50  int size = ori->size();
51  int counter = 0;
52 
53  double acc = 0.0;
54  for(int i = 0; i < size; i++) {
55  if(ori->data[i] > 0.0f && cmp->data[i] > 0.0f) {
56  double val = log2(ori->data[i] / cmp->data[i]);
57  acc += val * val;
58  counter++;
59  }
60  }
61 
62  if(counter > 0) {
63  acc = acc / double(counter);
64  return sqrt(acc);
65  } else {
66  return -3.0;
67  }
68 }
69 
70 } // end namespace pic
71 
72 #endif /* PIC_METRICS_LOG_RMSE_HPP */
73 
int size() const
size computes the number of values.
Definition: image.hpp:481
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
PIC_INLINE int log2(int n)
log2 computes logarithm in base 2 for integers.
Definition: math.hpp:302
PIC_INLINE double logRMSE(Image *ori, Image *cmp)
logRMSE computes root mean square error (RMSE) in the log_e domain.
Definition: log_rmse.hpp:36
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
#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...