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_GL_FILTERING_FILTER_EXPOSURE_FUSION_WEIGHTS_HPP
19 #define PIC_GL_FILTERING_FILTER_EXPOSURE_FUSION_WEIGHTS_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../gl/filtering/filter.hpp"
24 
25 namespace pic {
26 
31 {
32 protected:
36  void initShaders();
37 
41  void FragmentShader();
42 
43  float sigma_sq_2, mu;
44  float wC, wE, wS;
45 
46 public:
47 
54  FilterGLExposureFusionWeights(float wC = 1.0f, float wE = 1.0f, float wS = 1.0f) : FilterGL()
55  {
56  float sigma = 0.2f;
57  mu = 0.5f;
58  sigma_sq_2 = 2.0f * sigma * sigma;
59 
60  this->wC = wC >= 0.0f ? wC : 1.0f;
61  this->wE = wE >= 0.0f ? wE : 1.0f;
62  this->wS = wS >= 0.0f ? wS : 1.0f;
63 
64  //protected values are assigned/computed
65  initShaders();
66  }
67 
69  {
70  release();
71  }
72 
81  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
82  {
83  width = imgIn[0]->width;
84  height = imgIn[0]->height;
85  channels = 1;
86  frames = imgIn[0]->frames;
87  }
88 };
89 
91 {
93  (
94  uniform sampler2D u_tex; \n
95  uniform sampler2D u_tex_lum; \n
96  uniform float wC; \n
97  uniform float wE; \n
98  uniform float wS; \n
99  uniform float sigma_sq_2; \n
100  uniform float mu; \n
101  out vec4 f_color; \n
102 
103  void main(void) {
104  \n
105  ivec2 coords = ivec2(gl_FragCoord.xy);\n
106 
107  //saturation weight
108  vec3 color = texelFetch(u_tex, coords, 0).xyz;\n
109  float tmpMu = dot(color.xyz, vec3(1.0)) / 3.0;\n
110  vec3 tmpVar = color - vec3(tmpMu);\n
111  float pSat = sqrt( dot(tmpVar, tmpVar) / 3.0);\n
112  pSat = pow(pSat, wS);\n
113 
114  //well-exposedness weight
115  vec3 delta = color - vec3(mu);\n
116  float pExp = exp(-dot(delta, delta) / sigma_sq_2);\n
117  pExp = pow(pExp, wE);\n
118 
119  //contrast weight
120  float pCon = -4.0 * texelFetch(u_tex_lum, coords, 0).x+
121  texelFetch(u_tex_lum, coords + ivec2(1, 0), 0).x+\n
122  texelFetch(u_tex_lum, coords - ivec2(1, 0), 0).x+\n
123  texelFetch(u_tex_lum, coords + ivec2(0, 1), 0).x+\n
124  texelFetch(u_tex_lum, coords - ivec2(0, 1), 0).x;\n
125  pCon = pow(abs(pCon), wC);\n
126 
127  f_color = vec4(vec3(pCon * pExp * pSat + 1e-12), 1.0);\n
128  }\n
129  );
130 }
131 
133 {
134  FragmentShader();
135 
136  technique.initStandard("330", vertex_source, fragment_source, "FilterGLExposureFusionWeights");
137 
138  technique.bind();
139  technique.setUniform1i("u_tex_lum", 0);
140  technique.setUniform1i("u_tex", 1);
141  technique.setUniform1f("wC", wC);
142  technique.setUniform1f("wE", wE);
143  technique.setUniform1f("wS", wS);
144  technique.setUniform1f("mu", mu);
145  technique.setUniform1f("sigma_sq_2", sigma_sq_2);
146  technique.unbind();
147 }
148 
149 } // end namespace pic
150 
151 #endif /* PIC_GL_FILTERING_FILTER_EXPOSURE_FUSION_WEIGHTS_HPP */
152 
TechniqueGL technique
Definition: display.hpp:45
~FilterGLExposureFusionWeights()
Definition: filter_exposure_fusion_weights.hpp:68
float sigma_sq_2
Definition: filter_exposure_fusion_weights.hpp:43
float wE
Definition: filter_exposure_fusion_weights.hpp:44
float wS
Definition: filter_exposure_fusion_weights.hpp:44
void FragmentShader()
FragmentShader.
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
The FilterGLExposureFusionWeights class.
Definition: filter_exposure_fusion_weights.hpp:30
The FilterGL class.
Definition: filter.hpp:35
float mu
Definition: filter_exposure_fusion_weights.hpp:43
#define PIC_INLINE
Definition: base.hpp:33
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
float wC
Definition: filter_exposure_fusion_weights.hpp:44
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
FilterGLExposureFusionWeights(float wC=1.0f, float wE=1.0f, float wS=1.0f)
FilterGLExposureFusionWeights.
Definition: filter_exposure_fusion_weights.hpp:54
std::string fragment_source
Definition: display.hpp:57
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_exposure_fusion_weights.hpp:81
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236