PICCANTE  0.4
The hottest HDR imaging library!
tumblin_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_TONE_MAPPING_TUMBLIN_TMO_HPP
19 #define PIC_TONE_MAPPING_TUMBLIN_TMO_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../filtering/filter.hpp"
24 #include "../filtering/filter_luminance.hpp"
25 #include "../tone_mapping/tone_mapping_operator.hpp"
26 
27 namespace pic {
28 
33 {
34 protected:
35  float Ld_Max, Ld_a, Lw_a, C_Max;
37 
44  Image *ProcessAux(ImageVec imgIn, Image *imgOut)
45  {
46  updateImage(imgIn[0]);
47 
48  //compute luminance and its statistics
49  images[0] = flt_lum.Process(imgIn, images[0]);
50 
51  float Lw_Max;
52  images[0]->getMaxVal(NULL, &Lw_Max);
53 
54  float Lw_a_t;
55  if(Lw_a > 0.0f) {
56  Lw_a_t = Lw_a;
57  } else {
58  images[0]->getLogMeanVal(NULL, &Lw_a_t);
59  }
60 
61  float gamma_w = StevenCSF(Lw_a_t);
62  float gamma_d = StevenCSF(Ld_a);
63  float gamma_wd = gamma_w / (1.855f + 0.4f * logf(Ld_a));
64  float m = powf(C_Max, (gamma_wd - 1.0f) / 2.0f);
65 
66  float exponent = gamma_w / gamma_d;
67  float scale_norm = Lw_a;
68  float scale = Ld_a * m / Ld_Max;
69 
70  imgOut->assign(imgIn[0]);
71 
72  std::vector<float> param;
73  param.push_back(exponent);
74  param.push_back(scale_norm);
75  param.push_back(scale);
76  images[0]->applyFunctionParam(TumblinFun, param);
77 
78  (*imgOut) *= (*images[0]);
79 
80  return imgOut;
81  }
82 
89  static float TumblinFun(float Lw, std::vector<float> &param)
90  {
91  if(Lw > 0.0f) {
92  float Ld = powf(Lw / param[1], param[0]) * param[2];
93 
94  return Ld / Lw;
95  } else {
96  return 0.0f;
97  }
98  }
99 
100 public:
101 
109  TumblinTMO(float Ld_a = 20.0f, float Ld_Max = 100.0f, float C_Max = 100.0f, float Lw_a = -1.0f) : ToneMappingOperator()
110  {
111  images.push_back(NULL);
113  }
114 
116  {
117  release();
118  }
119 
127  void update(float Ld_a = 20.0f, float Ld_Max = 100.0f, float C_Max = 100.0f, float Lw_a = 1.0f)
128  {
129  this->Ld_a = Ld_a > 0.0f ? Ld_a : 20.0f;
130  this->Ld_Max = Ld_Max > 0.0f ? Ld_Max : 100.0f;
131  this->C_Max = C_Max > 0.0f ? C_Max : 100.0f;
132  this->Lw_a = Lw_a > 0.0f ? Lw_a : 1.0f;
133  }
134 
141  static Image *execute(Image *imgIn, Image *imgOut)
142  {
143  TumblinTMO ttmo;
144  return ttmo.Process(Single(imgIn), imgOut);
145  }
146 
152  static float StevenCSF(float x)
153  {
154  if(x <= 100.0f) {
155  return 1.855f + 0.4f * log10f(x + 2.3e-5f);
156  } else {
157  return 2.655f;
158  }
159  }
160 };
161 } // end namespace pic
162 
163 #endif /* PIC_TONE_MAPPING_TUMBLIN_TMO_HPP */
164 
void assign(const Image *imgIn)
assign
Image * Process(ImageVec imgIn, Image *imgOut=NULL)
Process.
Definition: tone_mapping_operator.hpp:120
void update(float Ld_a=20.0f, float Ld_Max=100.0f, float C_Max=100.0f, float Lw_a=1.0f)
update
Definition: tumblin_tmo.hpp:127
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
ImageVec images
Definition: tone_mapping_operator.hpp:35
float Ld_Max
Definition: tumblin_tmo.hpp:35
The ToneMappingOperator class.
Definition: tone_mapping_operator.hpp:31
float C_Max
Definition: tumblin_tmo.hpp:35
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: tumblin_tmo.hpp:141
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
~TumblinTMO()
Definition: tumblin_tmo.hpp:115
static float StevenCSF(float x)
StevenCSF.
Definition: tumblin_tmo.hpp:152
void updateImage(Image *imgIn)
updateImage
Definition: tone_mapping_operator.hpp:78
float Ld_a
Definition: tumblin_tmo.hpp:35
void release()
release
Definition: tone_mapping_operator.hpp:68
The TumblinTMO class.
Definition: tumblin_tmo.hpp:32
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static float TumblinFun(float Lw, std::vector< float > &param)
TumblinFun.
Definition: tumblin_tmo.hpp:89
float Lw_a
Definition: tumblin_tmo.hpp:35
TumblinTMO(float Ld_a=20.0f, float Ld_Max=100.0f, float C_Max=100.0f, float Lw_a=-1.0f)
TumblinTMO.
Definition: tumblin_tmo.hpp:109
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
Image * ProcessAux(ImageVec imgIn, Image *imgOut)
ProcessAux.
Definition: tumblin_tmo.hpp:44
FilterLuminance flt_lum
Definition: tumblin_tmo.hpp:36