PICCANTE  0.4
The hottest HDR imaging library!
filter_sigmoid_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_SIGMOID_TMO_HPP
19 #define PIC_FILTERING_FILTER_SIGMOID_TMO_HPP
20 
21 #include "../util/array.hpp"
22 #include "../util/std_util.hpp"
23 
24 #include "../filtering/filter.hpp"
25 #include "../filtering/filter_luminance.hpp"
26 
27 namespace pic {
28 
30 
34 class FilterSigmoidTMO: public Filter
35 {
36 protected:
37  bool temporal;
39  float c, alpha, epsilon, wp, wp_sq;
41 
47  float calculateEpsilon(ImageVec imgIn);
48 
55  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
56 
57 public:
58 \
63 
72  FilterSigmoidTMO(SIGMOID_MODE type, float alpha, float wp, float epsilon,
73  bool temporal);
74 
76  {
79  }
80 
89  void update(SIGMOID_MODE type, float alpha, float wp, float epsilon,
90  bool temporal);
91 
100  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
101  {
102  if(epsilon <= 0.0f || temporal) {
103  epsilon = calculateEpsilon(imgIn);
104  }
105 
108 
109  lum_weights = FilterLuminance::computeWeights(LT_CIE_LUMINANCE, imgIn[0]->channels, NULL);
110 
111  int whichImage = (imgIn.size() > 1) ? 1 : 0;
112  lum_weights_flt = FilterLuminance::computeWeights(LT_CIE_LUMINANCE, imgIn[whichImage]->channels, NULL);
113 
114  width = imgIn[0]->width;
115  height = imgIn[0]->height;
116  channels = imgIn[0]->channels;
117  frames = imgIn[0]->frames;
118  }
119 
126  static Image *execute(Image *imgIn, Image *imgOut)
127  {
128  FilterSigmoidTMO filter(SIG_TMO, 0.18f, 1e9f, -1.0f, false);
129  return filter.Process(Single(imgIn), imgOut);
130  }
131 };
132 
134 {
135  lum_weights = NULL;
136  lum_weights_flt = NULL;
137  update(SIG_TMO, 0.18f, 1e6f, -1.0f, false);
138 }
139 
141  float wp, float epsilon, bool temporal) : Filter()
142 {
143  lum_weights = NULL;
144  lum_weights_flt = NULL;
146 }
147 
149  float wp = 1e9f, float epsilon = -1.0f, bool temporal = false)
150 {
151  this->type = type;
152  this->alpha = alpha;
153  this->wp = wp;
154  this->wp_sq = wp * wp;
155 
156  this->epsilon = epsilon;
157  this->temporal = temporal;
158 }
159 
161 {
162  float tmpEpsilon, retEpsilon;
163 
164  switch(type) {
165  case SIG_TMO:
166  imgIn[0]->getLogMeanVal(NULL, &tmpEpsilon);
167  break;
168 
169  case SIG_TMO_WP:
170  imgIn[0]->getLogMeanVal(NULL, &tmpEpsilon);
171  break;
172 
173  case SIG_SDM:
174  tmpEpsilon = 1.0f;
175  break;
176 
177  default:
178  tmpEpsilon = 1.0f;
179  }
180 
181  if(temporal) {
182  if(epsilon > 0.0f) {
183  retEpsilon = (epsilon + tmpEpsilon) / 2.0f;
184  } else {
185  retEpsilon = tmpEpsilon;
186  }
187  } else {
188  retEpsilon = tmpEpsilon;
189  }
190 
191  return retEpsilon;
192 }
193 
195 {
196 
197  Image *img, *img_flt;
198 
199  img = src[0];
200 
201  if(src.size() > 1) {
202  img_flt = src[1];
203  } else {
204  img_flt = src[0];
205  }
206 
207  float alpha_over_epsilon = alpha / epsilon;
208 
209  for(int j = box->y0; j < box->y1; j++) {
210 
211  for(int i = box->x0; i < box->x1; i++) {
212 
213  float *p = (*img)(i, j);
214  float *p_flt = (*img_flt)(i, j);
215 
216  float *dstOut = (*dst)(i, j);
217 
218  float L = Arrayf::dot(p, lum_weights, img->channels);
219 
220  if(L > 0.0f) {
221  float L_flt = Arrayf::dot(p_flt, lum_weights_flt, img_flt->channels);
222 
223  float Lm = L * alpha_over_epsilon;
224  float Lm_flt = L_flt * alpha_over_epsilon;
225  float Ld;
226 
227  if(type == SIG_TMO_WP) {
228  Ld = L * (1.0f + L / wp_sq) / (1.0f + Lm_flt);
229  } else {
230  Ld = Lm / (1.0f + Lm_flt);
231  }
232 
233  for(int k = 0; k < dst->channels; k++) {
234  dstOut[k] = (p[k] * Ld) / L;
235  }
236  } else {
237  Arrayf::assign(0.0f, dstOut, dst->channels);
238  }
239  }
240  }
241 }
242 
243 } // end namespace pic
244 
245 #endif /* PIC_FILTERING_FILTER_SIGMOID_TMO_HPP */
246 
Definition: filter_luminance.hpp:28
~FilterSigmoidTMO()
Definition: filter_sigmoid_tmo.hpp:75
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
Definition: filter_sigmoid_tmo.hpp:29
float wp
Definition: filter_sigmoid_tmo.hpp:39
int channels
Definition: image.hpp:80
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
FilterSigmoidTMO()
FilterSigmoidTMO.
Definition: filter_sigmoid_tmo.hpp:133
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
SIGMOID_MODE type
Definition: filter_sigmoid_tmo.hpp:40
Definition: filter_sigmoid_tmo.hpp:29
float epsilon
Definition: filter_sigmoid_tmo.hpp:39
The Filter class.
Definition: filter.hpp:50
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: filter_sigmoid_tmo.hpp:126
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
float wp_sq
Definition: filter_sigmoid_tmo.hpp:39
void update(SIGMOID_MODE type, float alpha, float wp, float epsilon, bool temporal)
update
Definition: filter_sigmoid_tmo.hpp:148
bool temporal
Definition: filter_sigmoid_tmo.hpp:37
The FilterSigmoidTMO class.
Definition: filter_sigmoid_tmo.hpp:34
int y0
Definition: bbox.hpp:32
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_sigmoid_tmo.hpp:100
#define PIC_INLINE
Definition: base.hpp:33
float calculateEpsilon(ImageVec imgIn)
calculateEpsilon
Definition: filter_sigmoid_tmo.hpp:160
static T dot(T *data0, T *data1, int n)
dot
Definition: array.hpp:281
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_sigmoid_tmo.hpp:194
float c
Definition: filter_sigmoid_tmo.hpp:39
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
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
float alpha
Definition: filter_sigmoid_tmo.hpp:39
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
static float * computeWeights(LUMINANCE_TYPE type, int channels, float *weights)
computeWeights
Definition: filter_luminance.hpp:83
Definition: filter_sigmoid_tmo.hpp:29
float * lum_weights
Definition: filter_sigmoid_tmo.hpp:38
SIGMOID_MODE
Definition: filter_sigmoid_tmo.hpp:29
float * lum_weights_flt
Definition: filter_sigmoid_tmo.hpp:38