PICCANTE  0.4
The hottest HDR imaging library!
raman_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_RAMAN_TMO_HPP
19 #define PIC_TONE_MAPPING_RAMAN_TMO_HPP
20 
21 #include "../base.hpp"
22 #include "../util/std_util.hpp"
23 
24 #include "../filtering/filter_luminance.hpp"
25 #include "../filtering/filter_bilateral_2dg.hpp"
26 
27 #include "../tone_mapping/get_all_exposures.hpp"
28 #include "../tone_mapping/tone_mapping_operator.hpp"
29 
30 namespace pic {
31 
36 {
37 protected:
39 
46  Image *ProcessAux(ImageVec imgIn, Image *imgOut)
47  {
48  if(imgIn.size() > 1) {
49  return ProcessAuxStack(imgIn, imgOut);
50  } else {
51 
52  std::vector<float> fstops = getAllExposuresUniform(imgIn[0]);
53  ImageVec stack = getAllExposuresImages(imgIn[0], fstops);
54  //pic::ImageVec stack = getAllExposures(imgIn[0]);
55 
56  imgOut = ProcessAuxStack(stack, imgOut);
57 
58  stdVectorClear<Image>(stack);
59 
60  return imgOut;
61  }
62  }
63 
70  static float ramanFunction(float x, std::vector<float>& param)
71  {
72  return fabsf(x) + param[0];
73  }
74 
82  {
83  int n = int(imgIn.size());
84 
85  if(n < 2 || !ImageVecCheck(imgIn, -1)) {
86  return imgOut;
87  }
88 
89  //As reported in Raman and Chaudhuri Eurographics 2009 short paper
90  float K1 = 1.0f;
91  float K2 = 0.1f;
92  float C = 70.0f / 255.0f;
93 
94  int width = imgIn[0]->width;
95  int height = imgIn[0]->height;
96 
97  float sigma_s = K1 * MIN(width, height);
98 
99  updateImage(imgIn[0]);
100 
101  std::vector<float> param;
102  param.push_back(C);
103 
104  if(images[2] == NULL) {
105  //images[2] --> acc
106  images[2] = new Image(1, width, height, 1);
107  }
108 
109  images[2]->setZero();
110 
111  //accumulate into a Pyramid
112  #ifdef PIC_DEBUG
113  printf("Blending...");
114  #endif
115 
116  imgOut->setZero();
117 
118  for(int j = 0; j < n; j++) {
119  images[0] = flt_lum.Process(Single(imgIn[j]), images[0]);
120 
121  float min, max;
122 
123  images[0]->getMinVal(NULL, &min);
124  images[0]->getMaxVal(NULL, &max);
125  float sigma_r = K2 * (max - min);
126 
127  images[1] = FilterBilateral2DG::execute(images[0], images[1], sigma_s, sigma_r);
128  *images[1] -= *images[0];
129  images[1]->applyFunctionParam(ramanFunction, param);
130 
131  *images[2] += *images[1];
132 
133  //normalization
134  auto tmp = imgIn[j]->clone();
135  *tmp *= *images[1];
136 
137  *imgOut += *tmp;
138  }
139 
140  *imgOut /= *images[2];
141 
142  #ifdef PIC_DEBUG
143  printf(" ok\n");
144  #endif
145 
146  return imgOut;
147  }
148 
149 public:
150 
155  {
156  setToANullVector<Image>(images, 3);
157  }
158 
160  {
161  release();
162  }
163 
170  static Image* execute(Image *imgIn, Image *imgOut)
171  {
172  RamanTMO rtmo;
173  return rtmo.Process(Single(imgIn), imgOut);
174  }
175 
182  static Image* executeStack(ImageVec imgIn, Image *imgOut)
183  {
184  RamanTMO rtmo;
185  return rtmo.Process(imgIn, imgOut);
186  }
187 };
188 
189 } // end namespace pic
190 
191 #endif /* PIC_TONE_MAPPING_RAMAN_TMO_HPP */
192 
~RamanTMO()
Definition: raman_tmo.hpp:159
PIC_INLINE bool ImageVecCheck(ImageVec &imgIn, int minInputImages)
ImageVecCheck.
Definition: image_vec.hpp:147
Image * Process(ImageVec imgIn, Image *imgOut=NULL)
Process.
Definition: tone_mapping_operator.hpp:120
void setZero()
setZero sets data to 0.0f.
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
ImageVec images
Definition: tone_mapping_operator.hpp:35
The ToneMappingOperator class.
Definition: tone_mapping_operator.hpp:31
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: raman_tmo.hpp:170
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
Image * ProcessAuxStack(ImageVec imgIn, Image *imgOut)
ProcessAuxStack.
Definition: raman_tmo.hpp:81
static Image * executeStack(ImageVec imgIn, Image *imgOut)
executeStack
Definition: raman_tmo.hpp:182
void updateImage(Image *imgIn)
updateImage
Definition: tone_mapping_operator.hpp:78
void release()
release
Definition: tone_mapping_operator.hpp:68
FilterLuminance flt_lum
Definition: raman_tmo.hpp:38
Image * ProcessAux(ImageVec imgIn, Image *imgOut)
ProcessAux.
Definition: raman_tmo.hpp:46
static Image * execute(Image *imgIn, Image *imgOut, float sigma_s, float sigma_r)
execute
Definition: filter_bilateral_2dg.hpp:101
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
PIC_INLINE ImageVec getAllExposuresImages(Image *imgIn, std::vector< float > &fstops, float gamma=2.2f)
getAllExposuresImages converts an image into a stack of images.
Definition: get_all_exposures.hpp:144
The RamanTMO class.
Definition: raman_tmo.hpp:35
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 float ramanFunction(float x, std::vector< float > &param)
ramanFunction
Definition: raman_tmo.hpp:70
int width
Definition: image.hpp:80
RamanTMO()
RamanTMO.
Definition: raman_tmo.hpp:154
PIC_INLINE std::vector< float > getAllExposuresUniform(Image *imgIn)
getAllExposuresUniform computes all required exposure values for reconstructing the input image using...
Definition: get_all_exposures.hpp:87