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_TONE_MAPPING_DURAND_TMO_HPP
19 #define PIC_TONE_MAPPING_DURAND_TMO_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../util/string.hpp"
24 #include "../filtering/filter.hpp"
25 #include "../filtering/filter_luminance.hpp"
26 #include "../algorithms/bilateral_separation.hpp"
27 #include "../tone_mapping/tone_mapping_operator.hpp"
28 
29 namespace pic {
30 
35 {
36 public:
37 
40 
44  DurandTMO(float target_contrast = 5.0f)
45  {
46  images.push_back(NULL);
47  images.push_back(NULL);
48  images.push_back(NULL);
50  }
51 
53  {
54  release();
55  }
56 
61  void update(float target_contrast = 5.0f)
62  {
63  if(target_contrast <= 0.0f) {
64  target_contrast = 5.0f;
65  }
66 
67  this->target_contrast = target_contrast;
68  }
69 
76  Image *ProcessAux(ImageVec imgIn, Image *imgOut)
77  {
78  updateImage(imgIn[0]);
79 
80  //luminance image
81  images[2] = flt_lum.Process(imgIn, images[2]);
82 
83  //bilateral filter seperation
84  bilateralSeparation(images[2], images, -1.0f, 0.4f, true);
85 
86  Image *base = images[0];
87  Image *detail = images[1];
88 
89  float min_log_base, max_log_base;
90  base->getMinVal(NULL, &min_log_base);
91  base->getMaxVal(NULL, &max_log_base);
92 
93  float compression_factor = log10fPlusEpsilon(target_contrast) / (max_log_base - min_log_base);
94  float log_absoulte = compression_factor * max_log_base;
95 
96  *base *= compression_factor;
97  *base += detail;
98  *base -= log_absoulte;
100 
101  *imgOut = *imgIn[0];
102  *imgOut *= base;
103  *imgOut /= images[2];
104 
105  imgOut->removeSpecials();
106 
107  return imgOut;
108  }
109 
116  static Image *execute(Image *imgIn, Image *imgOut)
117  {
118  DurandTMO dtmo(5.0f);
119  return dtmo.Process(Single(imgIn), imgOut);
120  }
121 };
122 
123 } // end namespace pic
124 
125 #endif /* PIC_TONE_MAPPING_DURAND_TMO_HPP */
126 
PIC_INLINE void bilateralSeparation(Image *imgIn, ImageVec &out, float sigma_s=-1.0f, float sigma_r=0.4f, bool bLogDomain=false)
bilateralSeparation
Definition: bilateral_separation.hpp:35
Image * Process(ImageVec imgIn, Image *imgOut=NULL)
Process.
Definition: tone_mapping_operator.hpp:120
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: durand_tmo.hpp:38
The ToneMappingOperator class.
Definition: tone_mapping_operator.hpp:31
PIC_INLINE float log10fPlusEpsilon(float x)
log10fPlusEpsilon
Definition: math.hpp:355
The DurandTMO class.
Definition: durand_tmo.hpp:34
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
float * getMinVal(BBox *box, float *ret)
getMinVal computes the minimum value for the current Image.
float target_contrast
Definition: durand_tmo.hpp:39
void updateImage(Image *imgIn)
updateImage
Definition: tone_mapping_operator.hpp:78
void release()
release
Definition: tone_mapping_operator.hpp:68
PIC_INLINE float powf10fMinusEpsilon(float x)
powf10fMinusEpsilon
Definition: math.hpp:365
void applyFunction(float(*func)(float))
applyFunction is an operator that applies an input function to all values in data.
The Image class stores an image as buffer of float.
Definition: image.hpp:60
~DurandTMO()
Definition: durand_tmo.hpp:52
void removeSpecials()
removeSpecials removes NaN and +/-Inf values and sets them to 0.0f.
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
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: durand_tmo.hpp:116
DurandTMO(float target_contrast=5.0f)
DurandTMO.
Definition: durand_tmo.hpp:44
Image * ProcessAux(ImageVec imgIn, Image *imgOut)
ProcessAux.
Definition: durand_tmo.hpp:76
float * getMaxVal(BBox *box, float *ret)
getMaxVal computes the maximum value for the current Image.
void update(float target_contrast=5.0f)
update
Definition: durand_tmo.hpp:61