PICCANTE  0.4
The hottest HDR imaging library!
mae.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_MAE_HPP
19 #define PIC_METRICS_MAE_HPP
20 
21 #include <math.h>
22 
23 #include "../base.hpp"
24 #include "../image.hpp"
25 #include "../metrics/base.hpp"
26 
27 namespace pic {
28 
37 PIC_INLINE double MAE(Image *ori, Image *cmp, bool bLargeDifferences = false, METRICS_DOMAIN type = MD_LIN)
38 {
39  if(ori == NULL || cmp == NULL) {
40  return -2.0;
41  }
42 
43  if(!ori->isValid() || !cmp->isValid()) {
44  return -4.0;
45  }
46 
47  if(!ori->isSimilarType(cmp)) {
48  return -1.0;
49  }
50 
51  int size = ori->size();
52 
53  double largeDifferences = C_LARGE_DIFFERENCES;
54 
55  if(!bLargeDifferences) {
56  largeDifferences = FLT_MAX;
57  }
58 
59  double acc = 0.0;
60  int count = 0;
61  for(int i = 0; i < size; i++) {
62  double o_val = changeDomain(ori->data[i], type);
63  double c_val = changeDomain(cmp->data[i], type);
64 
65  double delta = fabs(o_val - c_val);
66 
67  if(delta < largeDifferences) {
68  acc += delta;
69  count++;
70  }
71  }
72 
73  return acc / double(count);
74 }
75 
76 } // end namespace pic
77 
78 #endif /* PIC_METRICS_MAE_HPP */
79 
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
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...
METRICS_DOMAIN
Definition: base.hpp:30
const double C_LARGE_DIFFERENCES
Definition: base.hpp:27
PIC_INLINE double MAE(Image *ori, Image *cmp, bool bLargeDifferences=false, METRICS_DOMAIN type=MD_LIN)
MAE computes the mean abosulute errore (MAE) between two images.
Definition: mae.hpp:37
Definition: base.hpp:30