PICCANTE  0.4
The hottest HDR imaging library!
filter_drago_tmo.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_FILTERING_FILTER_DRAGO_TMO_HPP
19 #define PIC_FILTERING_FILTER_DRAGO_TMO_HPP
20 
21 #include "../util/array.hpp"
22 #include "../filtering/filter.hpp"
23 #include "../filtering/filter_luminance.hpp"
24 
25 namespace pic {
26 
30 class FilterDragoTMO: public Filter
31 {
32 protected:
34  float b, Ld_Max, Lw_Max, Lw_a;
35 
42  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
43 
44 public:
49 
57  FilterDragoTMO(float Ld_Max, float b, float Lw_Max, float Lwa);
58 
66  void update(float Ld_Max, float b, float Lw_Max, float Lwa);
67 };
68 
70 {
71  update(100.0f, 0.95f, 1e6f, 0.5f);
72 }
73 
74 PIC_INLINE FilterDragoTMO::FilterDragoTMO(float Ld_Max, float b, float Lw_Max,
75  float Lw_a) : Filter()
76 {
78 }
79 
80 PIC_INLINE void FilterDragoTMO::update(float Ld_Max, float b, float Lw_Max,
81  float Lw_a)
82 {
83  //protected values are assigned/computed
84  this->Ld_Max = (Ld_Max > 0.0f) ? Ld_Max : 100.0f;
85  this->b = (b > 0.0f) ? b : 0.95f;
86  this->Lw_Max = (Lw_Max > 0.0f) ? Lw_Max : 1e6f;
87  this->Lw_a = (Lw_a > 0.0f) ? Lw_a : 0.5f;
88 
89  //constants
90  Lw_a_scaled = this->Lw_a / powf(1.0f + b - 0.85f, 5.0f);
91  Lw_Max_scaled = this->Lw_Max / Lw_a_scaled;
92 
93  constant1 = logf(b) / logf(0.5f);
94  constant2 = (Ld_Max / 100.0f) / (log10f(1.0f + Lw_Max_scaled));
95 }
96 
98 {
99  int channels = src[0]->channels;
100 
101  for(int j = box->y0; j < box->y1; j++) {
102 
103  for(int i = box->x0; i < box->x1; i++) {
104 
105  float *dataIn = (*src[0])(i, j);
106  float *dataLum = (*src[1])(i, j);
107  float *dataOut = (*dst )(i, j);
108 
109  if(dataLum[0] > 0.0f) {
110  float L_scaled = dataLum[0] / Lw_a_scaled;
111 
112  float tmp = powf((L_scaled / Lw_Max_scaled), constant1);
113  float Ld = constant2 * logf(1.0f + L_scaled) / logf(2.0f + 8.0f * tmp);
114 
115  for(int k = 0; k < channels; k++) {
116  dataOut[k] = (dataIn[k] * Ld) / dataLum[0];
117  }
118  } else {
119  Array<float>::assign(0.0f, dataOut, src[0]->channels);
120  }
121  }
122  }
123 }
124 
125 } // end namespace pic
126 
127 #endif /* PIC_FILTERING_FILTER_DRAGO_TMO_HPP */
128 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
float Lw_Max
Definition: filter_drago_tmo.hpp:34
The Filter class.
Definition: filter.hpp:50
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_drago_tmo.hpp:97
float Lw_a
Definition: filter_drago_tmo.hpp:34
float Lw_Max_scaled
Definition: filter_drago_tmo.hpp:33
int y0
Definition: bbox.hpp:32
The FilterDragoTMO class.
Definition: filter_drago_tmo.hpp:30
float b
Definition: filter_drago_tmo.hpp:34
#define PIC_INLINE
Definition: base.hpp:33
float Lw_a_scaled
Definition: filter_drago_tmo.hpp:33
FilterDragoTMO()
FilterDragoTMO.
Definition: filter_drago_tmo.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
float constant2
Definition: filter_drago_tmo.hpp:33
float Ld_Max
Definition: filter_drago_tmo.hpp:34
Definition: bilateral_separation.hpp:25
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
float constant1
Definition: filter_drago_tmo.hpp:33
void update(float Ld_Max, float b, float Lw_Max, float Lwa)
update
Definition: filter_drago_tmo.hpp:80