PICCANTE  0.4
The hottest HDR imaging library!
schlick_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_SCHLICK_TMO_HPP
19 #define PIC_TONE_MAPPING_SCHLICK_TMO_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../util/array.hpp"
24 #include "../util/indexed_array.hpp"
25 
26 #include "../image.hpp"
27 #include "../filtering/filter.hpp"
28 #include "../filtering/filter_luminance.hpp"
29 #include "../tone_mapping/tone_mapping_operator.hpp"
30 
31 namespace pic {
32 
37 {
38 protected:
39  std::string mode;
40  int nBit;
41  float k, p, L0;
43 
50  Image *ProcessAux(ImageVec imgIn, Image *imgOut)
51  {
52  updateImage(imgIn[0]);
53 
54  //compute luminance and its statistics
55  float LMin, LMax;
56 
57  images[0] = flt_lum.Process(imgIn, images[0]);
58 
59  IntCoord ret;
61  LMin = IndexedArray<float>::percentile(images[0]->data, ret, 0.01f);
62 
63  images[0]->getMaxVal(NULL, &LMax);
64 
65  int channels = imgIn[0]->channels;
66 
67  bool bNonUniform = (mode.compare("nonuniform") == 0);
68 
69  float p_prime;
70  if((mode.compare("automatic") == 0) || bNonUniform) {
71  int nValues = 1 << nBit;
72  p_prime = L0 * LMax / (float(nValues) * LMin);
73  } else {
74  p_prime = p;
75  }
76 
77  float cSqrtLminLmax = sqrtf(LMin * LMax);
78 
79  #pragma omp parallel for
80  for(int i = 0; i < images[0]->size(); i++) {
81 
82  float Lw = images[0]->data[i];
83 
84  if(Lw > 0.0f) {
85  float p_prime_w = p_prime;
86 
87  if(bNonUniform) {
88  p_prime_w *= (1.0f - k + k * Lw / cSqrtLminLmax);
89  }
90 
91  float Ld = (p_prime_w * Lw) / ((p_prime_w - 1.0f) * Lw + LMax);
92 
93  int index = i * channels;
94  for(int j = 0; j < channels; j++) {
95  int k = index + j;
96  imgOut->data[k] = (imgIn[0]->data[k] * Ld) / Lw;
97  }
98  }
99  }
100 
101  return imgOut;
102  }
103 
104 public:
105 
114  SchlickTMO(std::string mode, float p, int nBit, float L0, float k) : ToneMappingOperator()
115  {
116  images.push_back(NULL);
117  update(mode, p, nBit, L0, k);
118  }
119 
121  {
122  release();
123  }
124 
133  void update(std::string mode = "automatic", float p = 200.0f, int nBit = 8, float L0 = 1.0f, float k = 0.5f)
134  {
135  this->mode = mode;
136  this->k = CLAMPi(k, 0.0f, 1.0f);
137  this->nBit = nBit < 1 ? 8 : nBit;
138  this->p = p < 1.0f ? 200.0f : p;
139  this->L0 = L0 < 0.0f ? 1.0f : L0;
140  }
141 
148  static Image *execute(Image *imgIn, Image *imgOut)
149  {
150  SchlickTMO stmo("automatic", 1.0f / 0.005f, 8, 1.0f, 0.5f);
151  return stmo.Process(Single(imgIn), imgOut);
152  }
153 };
154 } // end namespace pic
155 
156 #endif /* PIC_TONE_MAPPING_SCHLICK_TMO_HPP */
157 
~SchlickTMO()
Definition: schlick_tmo.hpp:120
float L0
Definition: schlick_tmo.hpp:41
Image * Process(ImageVec imgIn, Image *imgOut=NULL)
Process.
Definition: tone_mapping_operator.hpp:120
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
ImageVec images
Definition: tone_mapping_operator.hpp:35
FilterLuminance flt_lum
Definition: schlick_tmo.hpp:42
The ToneMappingOperator class.
Definition: tone_mapping_operator.hpp:31
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: schlick_tmo.hpp:148
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
float k
Definition: schlick_tmo.hpp:41
static void findSimple(T *data, int nData, bool(*func)(float), IntCoord &ret, int stride=1)
findSimple collects coordinates of data which satisfies a bool function func.
Definition: indexed_array.hpp:80
void updateImage(Image *imgIn)
updateImage
Definition: tone_mapping_operator.hpp:78
void release()
release
Definition: tone_mapping_operator.hpp:68
Image * ProcessAux(ImageVec imgIn, Image *imgOut)
ProcessAux.
Definition: schlick_tmo.hpp:50
std::vector< int > IntCoord
IntCoord.
Definition: indexed_array.hpp:30
The Image class stores an image as buffer of float.
Definition: image.hpp:60
The IndexedArray class.
Definition: indexed_array.hpp:36
static T percentile(T *data, IntCoord &coord, float percent)
percentile
Definition: indexed_array.hpp:181
void update(std::string mode="automatic", float p=200.0f, int nBit=8, float L0=1.0f, float k=0.5f)
update
Definition: schlick_tmo.hpp:133
int nBit
Definition: schlick_tmo.hpp:40
#define CLAMPi(x, a, b)
Definition: math.hpp:81
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
The SchlickTMO class.
Definition: schlick_tmo.hpp:36
SchlickTMO(std::string mode, float p, int nBit, float L0, float k)
SchlickTMO.
Definition: schlick_tmo.hpp:114
std::string mode
Definition: schlick_tmo.hpp:39
float p
Definition: schlick_tmo.hpp:41