PICCANTE  0.4
The hottest HDR imaging library!
relative_error.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_RELATIVE_ERROR_HPP
19 #define PIC_METRICS_RELATIVE_ERROR_HPP
20 
21 #include <math.h>
22 
23 #include "../base.hpp"
24 #include "../image.hpp"
25 
26 #include "../metrics/base.hpp"
27 
28 namespace pic {
29 
38 PIC_INLINE double RelativeError(Image *ori, Image *cmp, bool bLargeDifferences = false, METRICS_DOMAIN type = MD_LIN)
39 {
40  if(ori == NULL || cmp == NULL) {
41  return -2.0;
42  }
43 
44  if(!ori->isValid() || !cmp->isValid()) {
45  return -4.0;
46  }
47 
48  if(!ori->isSimilarType(cmp)) {
49  return -1.0;
50  }
51 
52  int size = ori->size();
53 
54  double relErr = 0.0f;
55  int count = 0;
56 
57  float largeDifferences = C_LARGE_DIFFERENCESf;
58  if(!bLargeDifferences) {
59  largeDifferences = FLT_MAX;
60  }
61 
62  for(int i = 0; i < size; i++) {
63  double o_val = double(changeDomain(ori->data[i], type));
64  double c_val = double(changeDomain(cmp->data[i], type));
65 
66  double delta = fabs(o_val - c_val);
67 
68  if(delta <= largeDifferences) {
69  count++;
70 
71  if(o_val > C_SINGULARITY) { //to avoid singularities
72  relErr += delta / o_val;
73  }
74  }
75  }
76 
77  if(count > 0) {
78  return relErr / double(count);
79  } else {
80  return -3.0;
81  }
82 }
83 
84 } // end namespace pic
85 
86 #endif /* PIC_METRICS_RELATIVE_ERROR_HPP */
87 
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
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
#define PIC_INLINE
Definition: base.hpp:33
PIC_INLINE double RelativeError(Image *ori, Image *cmp, bool bLargeDifferences=false, METRICS_DOMAIN type=MD_LIN)
RelativeError computes the relative error between two images.
Definition: relative_error.hpp:38
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
const double C_SINGULARITY
Definition: base.hpp:26
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
METRICS_DOMAIN
Definition: base.hpp:30
const float C_LARGE_DIFFERENCESf
Definition: base.hpp:28
Definition: base.hpp:30