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_TONE_MAPPING_HYBRID_TMO_HPP
19 #define PIC_TONE_MAPPING_HYBRID_TMO_HPP
20 
21 #include "../algorithms/segmentation_tmo_approx.hpp"
22 #include "../algorithms/pyramid.hpp"
23 #include "../filtering/filter_drago_tmo.hpp"
24 #include "../filtering/filter_sigmoid_tmo.hpp"
25 
26 namespace pic {
27 
31 class HybridTMO
32 {
33 protected:
38  float Ld_Max, b;
39 
41 
42 public:
47  {
48  imgDrago = NULL;
49  imgReinhard = NULL;
50  pyrA = NULL;
51  pyrB = NULL;
52  pyrWeight = NULL;
53  seg_map = NULL;
54 
55  Ld_Max = 100.0f;
56  b = 0.95f;
57  }
58 
64  void ReinhardApprox(float &alpha1, float &alpha2)
65  {
66  alpha1 = 1.0f / (2.0f * sqrtf(2.0f)); //sigma_s
67  alpha2 = powf(1.6f, 9.0f); //sigma_r
68  }
69 
76  Image *execute(Image *imgIn, Image *imgOut)
77  {
78  if(imgIn == NULL) {
79  return NULL;
80  }
81 
82  if(!imgIn->isValid()) {
83  return NULL;
84  }
85 
86  if(imgOut == NULL) {
87  imgOut = new Image(1, imgIn->width, imgIn->height, imgIn->channels);
88  }
89 
90  //compute segmentation map
91  seg_map = seg.Process(imgIn, seg_map);
92 
93  /* 0 ---> Drago et al. 2003
94  1 ---> Reinhard et al. 2002
95  LumZone = [-2, -1, 0, 1, 2, 3, 4];
96  TMOForZone = [ 0, 0, 1, 0, 1, 0, 0]; */
97 
98  int count[2];
99  count[0] = 0;
100  count[1] = 0;
101 
102  for(int i = 0; i < seg_map->size(); i++) {
103  int indx = int(seg_map->data[i]);
104 
105  if((indx == 2) || (indx == 4)) {
106  seg_map->data[i] = 1.0f;
107  count[1]++;
108  } else {
109  seg_map->data[i] = 0.0f;
110  count[0]++;
111  }
112  }
113 
114 #ifdef PIC_DEBUG
115  seg_map->Write("weight_map.pfm");
116 #endif
117 
118  //check if we have different zones
119  int value = 10;
120 
121  if(count[0] > 0 && count[1] > 0) {
122  value = 10;
123  }
124 
125  if(count[0] > 0 && count[1] == 0) {
126  value = 0;
127  }
128 
129  if(count[0] == 0 && count[1] > 0) {
130  value = 1;
131  }
132 
133  switch(value) {
134  case 0: {
135  fltDragoTMO.Process(Single(imgIn), imgOut);
136  }
137  break;
138 
139  case 1: {
140  fltReinhardTMO.Process(Single(imgIn), imgOut);
141  }
142  break;
143 
144  case 10: {
145  //Drago TMO
147 
148  if(pyrA == NULL) {
149  pyrA = new Pyramid(imgDrago, true);
150  } else {
151  pyrA->update(imgDrago);
152  }
153 
154  //Reinhard TMO
156 
157  if(pyrB == NULL) {
158  pyrB = new Pyramid(imgReinhard, true);
159  } else {
161  }
162 
163  //compute blending weight
164  if(pyrWeight == NULL) {
165  pyrWeight = new Pyramid(seg_map, false);
166  } else {
168  }
169 
170  //blend
172  pyrA->reconstruct(imgOut);
173  }
174  break;
175  }
176 
177  return imgOut;
178  }
179 };
180 
181 } // end namespace pic
182 
183 #endif /* PIC_TONE_MAPPING_HYBRID_TMO_HPP */
184 
Image * seg_map
Definition: hybrid_tmo.hpp:40
float Ld_Max
Definition: hybrid_tmo.hpp:38
void blend(Pyramid *pyr, Pyramid *weight)
blend
Definition: pyramid.hpp:379
int size() const
size computes the number of values.
Definition: image.hpp:481
Image * imgDrago
Definition: hybrid_tmo.hpp:40
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
float b
Definition: hybrid_tmo.hpp:38
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The Segmentation class.
Definition: segmentation_tmo_approx.hpp:35
The HybridTMO class.
Definition: hybrid_tmo.hpp:31
Pyramid * pyrWeight
Definition: hybrid_tmo.hpp:37
The FilterSigmoidTMO class.
Definition: filter_sigmoid_tmo.hpp:34
void ReinhardApprox(float &alpha1, float &alpha2)
ReinhardApprox.
Definition: hybrid_tmo.hpp:64
The FilterDragoTMO class.
Definition: filter_drago_tmo.hpp:30
void update(Image *img)
update recomputes the pyramid given a compatible image, img.
Definition: pyramid.hpp:280
Image * reconstruct(Image *imgOut)
reconstruct evaluates a Gaussian/Laplacian pyramid.
Definition: pyramid.hpp:320
The Image class stores an image as buffer of float.
Definition: image.hpp:60
HybridTMO()
HybridTMO.
Definition: hybrid_tmo.hpp:46
The Pyramid class.
Definition: pyramid.hpp:36
Pyramid * pyrB
Definition: hybrid_tmo.hpp:37
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
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
Pyramid * pyrA
Definition: hybrid_tmo.hpp:37
Image * imgReinhard
Definition: hybrid_tmo.hpp:40
Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: hybrid_tmo.hpp:76
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
Image * Process(Image *imgIn, Image *imgOut)
Process.
Definition: segmentation_tmo_approx.hpp:113
FilterSigmoidTMO fltReinhardTMO
Definition: hybrid_tmo.hpp:36
FilterDragoTMO fltDragoTMO
Definition: hybrid_tmo.hpp:35
Segmentation seg
Definition: hybrid_tmo.hpp:34