PICCANTE  0.4
The hottest HDR imaging library!
durand_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_GL_TONE_MAPPING_DURAND_TMO_HPP
19 #define PIC_GL_TONE_MAPPING_DURAND_TMO_HPP
20 
21 #include "../../util/string.hpp"
22 #include "../../util/math.hpp"
23 #include "../../util/std_util.hpp"
24 
25 #include "../../gl/filtering/filter_luminance.hpp"
26 #include "../../gl/filtering/filter_bilateral_2ds.hpp"
27 #include "../../gl/filtering/filter_op.hpp"
28 #include "../../gl/filtering/filter_durand_tmo.hpp"
29 
30 namespace pic {
31 
36 {
37 protected:
43 
44  std::vector<FilterGL*> filters;
45 
48 
49  float sigma_s, sigma_r;
50 
55  {
56  bAllocate = true;
57 
58  flt_lum = new FilterGLLuminance();
59  flt_log10 = new FilterGLOp("log(I0) * " + fromNumberToString(1.0f / logf(10.0f)), true, NULL, NULL);
62 
63  filters.push_back(flt_lum);
64  filters.push_back(flt_log10);
65  filters.push_back(flt_durand);
66  filters.push_back(flt_bil);
67  }
68 
69 public:
70 
75  {
76  bAllocate = false;
77 
78  this->sigma_r = 0.4f;
79 
81 
82  img_lum = NULL;
83  img_lum_base = NULL;
84 
85  min_log_base = -1e10f;
86  max_log_base = -1e10f;
87 
88  this->bStatisticsRecompute = bStatisticsRecompute;
89  }
90 
92  {
93  stdVectorClear<FilterGL>(filters);
94 
95  if(img_lum != NULL) {
96  delete img_lum;
97  img_lum = NULL;
98  }
99 
100  if(img_lum_base != NULL) {
101  delete img_lum_base;
102  img_lum_base = NULL;
103  }
104  }
105 
111  {
112  this->target_contrast = target_contrast > 0.0f ? target_contrast : 5.0f;
113  }
114 
121  ImageGL *execute(ImageGL *imgIn, ImageGL *imgOut = NULL)
122  {
123  if(imgIn == NULL) {
124  return imgOut;
125  }
126 
127  if(!bAllocate) {
128  allocateFilters();
129  }
130 
131  this->sigma_s = MAX(imgIn->widthf, imgIn->heightf) * 0.02f;
133 
134  img_lum = flt_lum->Process(SingleGL(imgIn), img_lum);
135 
137 
139 
140  if(bStatisticsRecompute || (min_log_base < -1e6f) || (max_log_base < -1e6f)) {
143  }
144 
145  float compression_factor = log10fPlusEpsilon(target_contrast) / (max_log_base - min_log_base);
146  float log_absoulte = compression_factor * max_log_base;
147 
148  flt_durand->update(compression_factor, log_absoulte);
149 
150  return flt_durand->Process(TripleGL(imgIn, img_lum, img_lum_base), imgOut);
151  }
152 };
153 
154 } // end namespace pic
155 
156 #endif /* PIC_GL_TONE_MAPPING_DURAND_TMO_HPP */
157 
~DurandTMOGL()
Definition: durand_tmo.hpp:91
std::string fromNumberToString(T num)
fromNumberToString converts a number into a string.
Definition: string.hpp:102
float heightf
Definition: filter_radial_basis_function.hpp:84
PIC_INLINE float log10fPlusEpsilon(float x)
log10fPlusEpsilon
Definition: math.hpp:355
Definition: filter_bilateral_2ds.hpp:29
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
Definition: filter_op.hpp:28
float max_log_base
Definition: durand_tmo.hpp:47
ImageGL * img_lum
Definition: durand_tmo.hpp:42
The ImageGL class.
Definition: image.hpp:42
float * getMinVal(float *ret=NULL)
getMinVal
Definition: image.hpp:431
ImageGL * img_lum_base
Definition: durand_tmo.hpp:42
ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut=NULL)
execute
Definition: durand_tmo.hpp:121
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
The FilterGLBilateral2DS class.
Definition: filter_bilateral_2ds.hpp:63
DurandTMOGL(float target_contrast=5.0f, bool bStatisticsRecompute=true)
DurandTMOGL.
Definition: durand_tmo.hpp:74
float * getMaxVal(float *ret=NULL)
getMaxVal
Definition: image.hpp:443
FilterGLBilateral2DS * flt_bil
Definition: durand_tmo.hpp:39
float sigma_s
Definition: durand_tmo.hpp:49
float sigma_r
Definition: durand_tmo.hpp:49
void update(float target_contrast)
update
Definition: durand_tmo.hpp:110
float min_log_base
Definition: durand_tmo.hpp:47
float widthf
Definition: filter_radial_basis_function.hpp:84
PIC_INLINE ImageGLVec TripleGL(ImageGL *img1, ImageGL *img2, ImageGL *img3)
TripleGL creates a triple for filters input.
Definition: image_vec.hpp:67
The FilterGLDurandTMO class.
Definition: filter_durand_tmo.hpp:31
bool bAllocate
Definition: durand_tmo.hpp:46
bool bStatisticsRecompute
Definition: durand_tmo.hpp:46
Definition: bilateral_separation.hpp:25
FilterGLDurandTMO * flt_durand
Definition: durand_tmo.hpp:41
float target_contrast
Definition: durand_tmo.hpp:47
The DurandTMOGL class.
Definition: durand_tmo.hpp:35
#define MAX(a, b)
Definition: math.hpp:73
The FilterGLLuminance class.
Definition: filter_luminance.hpp:30
void update(float compression_factor, float log_absolute)
update
FilterGLOp * flt_log10
Definition: durand_tmo.hpp:40
void allocateFilters()
allocateFilters
Definition: durand_tmo.hpp:54
FilterGLLuminance * flt_lum
Definition: durand_tmo.hpp:38
void update(float sigma_s, float sigma_r, BF_TYPE type)
update
std::vector< FilterGL * > filters
Definition: durand_tmo.hpp:44