PICCANTE  0.4
The hottest HDR imaging library!
hybrid_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_HYBRID_TMO_HPP
19 #define PIC_GL_TONE_MAPPING_HYBRID_TMO_HPP
20 
22 
24 
26 
28 
30 
31 namespace pic {
32 
37 {
38 protected:
45  float Ld_Max, b;
47 
50 
55  {
56  bAllocate = true;
57  flt_drago = new DragoTMOGL();
60  }
61 
62 public:
63 
68  {
69  bAllocate = false;
70  bFirst = true;
71 
72  flt_reinhard = NULL;
73  flt_reinhard = NULL;
74  check = NULL;
75 
76  imgDrago = NULL;
77  imgReinhard = NULL;
78  pyrA = NULL;
79  pyrB = NULL;
80  pyrWeight = NULL;
81  seg_map = NULL;
82  remapped = NULL;
83 
84  Ld_Max = 100.0f;
85  b = 0.95f;
86  }
87 
89  {
90 
91  }
92 
99  ImageGL *Process(ImageGL *imgIn, ImageGL *imgOut)
100  {
101  if(imgIn == NULL) {
102  return NULL;
103  }
104 
105  if(!imgIn->isValid()) {
106  return NULL;
107  }
108 
109  if(imgOut == NULL) {
110  imgOut = new ImageGL(1, imgIn->width, imgIn->height, imgIn->channels,
111  IMG_GPU, GL_TEXTURE_2D);
112  }
113 
114  if(bAllocate) {
115  allocateFilters();
116  }
117 
118  //compute segmentation map
119 #ifdef PIC_DEBUG
120  float ms, tot_ms;
121  GLuint testTQ1 = glBeginTimeQuery();
122 #endif
123 
124  //compute segmentation map
125  seg_map = seg.execute(imgIn, seg_map);
126 
127 
128 #ifdef PIC_DEBUG
129  GLuint64EXT timeVal = glEndTimeQuery(testTQ1);
130  ms = float(double(timeVal) / 1000000.0);
131  tot_ms = ms;
132  printf("GPU time segmentation: %f ms\n", ms);
133 #endif
135 
136  /* 0 ---> Drago et al. 2003
137  1 ---> Reinhard et al. 2002
138  LumZone = [-2, -1, 0, 1, 2, 3, 4];
139  TMOForZone = [ 0, 0, 1, 0, 1, 0, 0]; */
140 
141  //Checking if we have different zones
142 #ifdef PIC_DEBUG
143  testTQ1 = glBeginTimeQuery();
144 #endif
145 
146  float check_value;
147  remapped->getVal(&check_value, check);
148  int value = int(check_value);
149 
150 #ifdef PIC_DEBUG
151  timeVal = glEndTimeQuery(testTQ1);
152  ms = float(double(timeVal) / 1000000.0);
153  tot_ms += ms;
154 
155  printf("GPU time Checking Different Zones: %f ms\n", ms);
156  testTQ1 = glBeginTimeQuery();
157 #endif
158 
159  switch(value) {
160  case 0: {
161  imgOut = flt_drago->execute(imgIn, imgOut);
162  }
163  break;
164 
165  case 1: {
166  flt_reinhard->update(-1.0f, -1.0f, true);
167  imgOut = flt_reinhard->execute(imgIn, imgOut);
168  }
169  break;
170 
171  case 10: {
172  //Drago TMO
173  imgDrago = flt_drago->execute(imgIn, imgDrago);
175  imgDrago->Write("tmp.pfm");
176 
177  //Reinhard TMO
179 
180  //generate/update pryamids
181  if(pyrA == NULL) {
182  pyrA = new PyramidGL(imgDrago, true);
183  } else {
184  pyrA->update(imgDrago);
185  }
186 
187  if(pyrB == NULL) {
188  pyrB = new PyramidGL(imgReinhard, true);
189  } else {
191  }
192 
193  if(pyrWeight == NULL) {
194  pyrWeight = new PyramidGL(remapped, false);
195  } else {
197  }
198 
199  //Blending
201  imgOut = pyrA->reconstruct(imgOut);
202  }
203  break;
204  }
205 
206 
207 #ifdef PIC_DEBUG
208  timeVal = glEndTimeQuery(testTQ1);
209  ms = float(double(timeVal) / 1000000.0);
210  tot_ms += ms;
211  printf("GPU time Tone Mapping+Blending: %f ms\n", ms);
212 
213  if(!bFirst) {
214  printf("Total time: %f\n", tot_ms);
215  } else {
216  bFirst = false;
217  }
218 #endif
219 
220  return imgOut;
221  }
222 };
223 
224 } // end namespace pic
225 
226 #endif /* PIC_GL_TONE_MAPPING_HYBRID_TMO_HPP */
227 
int channels
Definition: filter_radial_basis_function.hpp:80
DragoTMOGL * flt_drago
Definition: hybrid_tmo.hpp:48
ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut=NULL)
execute
Definition: drago_tmo.hpp:98
The HybridTMOGL class.
Definition: hybrid_tmo.hpp:36
ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut=NULL)
execute
Definition: reinhard_tmo.hpp:161
ImageGL * imgReinhard
Definition: hybrid_tmo.hpp:43
void update(ImageGL *img)
update
The PyramidGL class.
Definition: pyramid.hpp:35
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
Definition: filter_radial_basis_function.hpp:1148
GLuint glBeginTimeQuery()
glBeginTimeQuery
Definition: timings.hpp:29
The FilterGLRemapping class.
Definition: filter_remapping.hpp:30
bool bFirst
Definition: hybrid_tmo.hpp:46
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
The DragoTMOGL class.
Definition: drago_tmo.hpp:33
float Ld_Max
Definition: hybrid_tmo.hpp:45
GLuint64 glEndTimeQuery(GLuint64 ret)
glEndTimeQuery
Definition: timings.hpp:46
ImageGL * imgDrago
Definition: hybrid_tmo.hpp:43
ImageGL * Process(ImageGL *imgIn, ImageGL *imgOut)
Process.
Definition: hybrid_tmo.hpp:99
The ImageGL class.
Definition: image.hpp:42
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
Definition: filter_radial_basis_function.hpp:1924
PyramidGL * pyrA
Definition: hybrid_tmo.hpp:44
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
The ReinhardTMOGL class.
Definition: reinhard_tmo.hpp:35
The ReduxGL class.
Definition: redux.hpp:32
void blend(PyramidGL *pyr, PyramidGL *weight)
blend
HybridTMOGL()
HybridTMOGL.
Definition: hybrid_tmo.hpp:67
The SegmentationGL class.
Definition: segmentation_tmo_approx.hpp:32
~HybridTMOGL()
Definition: hybrid_tmo.hpp:88
void update(float alpha, float phi, bool bGlobal=true)
update
Definition: reinhard_tmo.hpp:147
ImageGL * seg_map
Definition: hybrid_tmo.hpp:42
int width
Definition: filter_radial_basis_function.hpp:80
PyramidGL * pyrWeight
Definition: hybrid_tmo.hpp:44
PyramidGL * pyrB
Definition: hybrid_tmo.hpp:44
float b
Definition: hybrid_tmo.hpp:45
SegmentationGL seg
Definition: hybrid_tmo.hpp:39
bool bAllocate
Definition: hybrid_tmo.hpp:46
ReinhardTMOGL * flt_reinhard
Definition: hybrid_tmo.hpp:49
void loadToMemory()
loadToMemory
void allocateFilters()
allocateFilters
Definition: hybrid_tmo.hpp:54
Definition: bilateral_separation.hpp:25
static ReduxGL * createCheck()
createCheck
Definition: redux.hpp:183
ReduxGL * check
Definition: hybrid_tmo.hpp:41
ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut)
execute
Definition: segmentation_tmo_approx.hpp:110
float * getVal(float *ret, ReduxGL *flt)
getVal
Definition: image.hpp:399
FilterGLRemapping remap
Definition: hybrid_tmo.hpp:40
Definition: image.hpp:37
ImageGL * reconstruct(ImageGL *imgOut)
reconstruct
int height
Definition: filter_radial_basis_function.hpp:80
ImageGL * remapped
Definition: hybrid_tmo.hpp:43