PICCANTE  0.4
The hottest HDR imaging library!
filter_exposure_fusion_weights.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_EXPOSURE_FUSION_WEIGHTS
19 #define PIC_FILTERING_FILTER_EXPOSURE_FUSION_WEIGHTS
20 
21 #include "../filtering/filter.hpp"
22 
23 #include "../colors/saturation.hpp"
24 
25 namespace pic {
26 
31 {
32 protected:
33  float wC, wE, wS;
34  float mu, sigma_sq_2;
35 
42  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
43  {
44  for(int j = box->y0; j < box->y1; j++) {
45 
46  for(int i = box->x0; i < box->x1; i++) {
47 
48  float *pCur0 = (*src[0])(i, j);
49  float *pCur1 = (*src[1])(i, j);
50 
51  //saturation
52  float pSat = computeSaturation(pCur1, src[1]->channels);
53 
54  //contrast
55  float *pCurN0 = (*src[0])(i, j + 1);
56  float *pCurS0 = (*src[0])(i, j - 1);
57  float *pCurE0 = (*src[0])(i + 1, j);
58  float *pCurW0 = (*src[0])(i - 1, j);
59 
60  float pCon = fabsf(-4.0f * pCur0[0] +
61  pCurN0[0] + pCurS0[0] + pCurE0[0] + pCurW0[0]);
62 
63  //well-exposedness
64  float pExp = 0.0f;
65  for(int c = 0; c < src[1]->channels; c++) {
66  float delta = pCur1[c] - mu;
67  pExp += delta * delta;
68  }
69  pExp = expf(-pExp / sigma_sq_2);
70 
71  //final weights
72  float *out = (*dst)(i, j);
73  out[0] = powf(pCon, wC) * powf(pExp, wE) * powf(pSat, wS) + 1e-12f;
74  out[0] = CLAMPi(out[0], 0.0f, 1.0f);
75  }
76  }
77  }
78 
79 public:
80 
87  FilterExposureFusionWeights(float wC = 1.0f, float wE = 1.0f, float wS = 1.0f) : Filter()
88  {
89  update(wC, wE, wS);
90  minInputImages = 2;
91  }
92 
99  void update(float wC = 1.0f, float wE = 1.0f, float wS = 1.0f)
100  {
101  float sigma = 0.2f;
102 
103  mu = 0.5f;
104  sigma_sq_2 = 2.0f * sigma * sigma;
105 
106  this->wC = wC > 0.0f ? MIN(wC, 1.0f) : 1.0f;
107  this->wE = wE > 0.0f ? MIN(wE, 1.0f) : 1.0f;
108  this->wS = wS > 0.0f ? MIN(wS, 1.0f) : 1.0f;
109  }
110 };
111 
112 } // end namespace pic
113 
114 #endif /* PIC_FILTERING_FILTER_EXPOSURE_FUSION_WEIGHTS */
115 
float mu
Definition: filter_exposure_fusion_weights.hpp:34
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
PIC_INLINE float computeSaturation(float *data, int channels=3)
computeSaturation
Definition: saturation.hpp:33
FilterExposureFusionWeights(float wC=1.0f, float wE=1.0f, float wS=1.0f)
FilterExposureFusionWeights.
Definition: filter_exposure_fusion_weights.hpp:87
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
void update(float wC=1.0f, float wE=1.0f, float wS=1.0f)
update
Definition: filter_exposure_fusion_weights.hpp:99
The Filter class.
Definition: filter.hpp:50
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_exposure_fusion_weights.hpp:42
float sigma_sq_2
Definition: filter_exposure_fusion_weights.hpp:34
int y0
Definition: bbox.hpp:32
int minInputImages
Definition: filter_radial_basis_function.hpp:56
The FilterExposureFusionWeights class.
Definition: filter_exposure_fusion_weights.hpp:30
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
#define CLAMPi(x, a, b)
Definition: math.hpp:81
float wC
Definition: filter_exposure_fusion_weights.hpp:33
Definition: bilateral_separation.hpp:25
float wE
Definition: filter_exposure_fusion_weights.hpp:33
float wS
Definition: filter_exposure_fusion_weights.hpp:33