PICCANTE  0.4
The hottest HDR imaging library!
filter_assemble_hdr.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_ASSEMBLE_HDR_HPP
19 #define PIC_FILTERING_FILTER_ASSEMBLE_HDR_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 #include "../util/array.hpp"
24 
25 #include "../algorithms/camera_response_function.hpp"
26 
27 namespace pic {
28 
39 
44 {
45 protected:
49  float delta_value;
50 
57  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
58  {
59  int width = dst->width;
60  int channels = dst->channels;
61 
62  int n = int(src.size());
63 
64  float t_min = src[0]->exposure;
65  int index = 0;
66  for(int j = 1; j < n; j++) {
67  if(src[j]->exposure < t_min) {
68  t_min = src[j]->exposure;
69  index = j;
70  }
71  }
72 
73  float *acc = new float[channels];
74  float *totWeight = new float[channels];
75 
76  for(int j = box->y0; j < box->y1; j++) {
77  int ind = j * width;
78 
79  for(int i = box->x0; i < box->x1; i++) {
80  int c = (ind + i) * channels;
81 
82  Arrayf::assign(0.0f, acc, channels);
83  Arrayf::assign(0.0f, totWeight, channels);
84 
85  float max_val_saturation = 1.0f;
86  float max_val_saturation_fb = -1.0f;
87 
88  //for each exposure...
89  for(int l = 0; l < n; l++) {
90 
91  float x = Arrayf::sum(&src[l]->data[c], channels);
92  x /= dst->channelsf;
93 
94  float t_mvs = x / t_min;
95 
96  max_val_saturation_fb = MAX(max_val_saturation_fb, t_mvs);
97 
98  if(l == index) {
99  max_val_saturation = t_mvs;
100  }
101 
102  float weight = weightFunction(x, weight_type);
103 
104  if(domain == HRD_SQ) {
105  weight *= (src[l]->exposure * src[l]->exposure);
106  }
107 
108  for(int k = 0; k < channels; k++) {
109  float x_lin = crf->remove(src[l]->data[c + k], k);
110 
111  //merge HDR pixels
112  switch(domain) {
113  case HRD_LIN: {
114  acc[k] += (weight * x_lin) / src[l]->exposure;
115  } break;
116 
117  case HRD_LOG: {
118  acc[k] += weight * (logf(x_lin + delta_value) - logf(src[l]->exposure));
119  } break;
120 
121  case HRD_SQ: {
122  acc[k] += (weight * x_lin) * src[l]->exposure;
123  } break;
124  }
125 
126  totWeight[k] += weight;
127  }
128  }
129 
130  bool bSaturated = false;
131  for(int k = 0; k < channels; k++) {
132  bSaturated = bSaturated || (totWeight[k] < 1e-4f);
133  }
134 
135  if(!bSaturated) {
136  for(int k = 0; k < channels; k++) {
137  acc[k] /= totWeight[k];
138  if(domain == HRD_LOG) {
139  acc[k] = expf(acc[k]);
140  }
141  dst->data[c + k] = acc[k];
142  }
143  } else {
144  max_val_saturation = MAX(max_val_saturation_fb, max_val_saturation);
145  Arrayf::assign(max_val_saturation, &dst->data[c], channels);
146  }
147  }
148  }
149 
150  delete[] totWeight;
151  delete[] acc;
152  }
153 
154 public:
155 
163  {
165  minInputImages = 2;
166 
167  //a numerical stability value when assembling images in the log-domain
168  this->delta_value = 1.0 / 65536.0f;
169  }
170 
178  {
179  this->crf = crf;
180 
181  this->weight_type = weight_type;
182 
183  this->domain = domain;
184  }
185 };
186 
187 } // end namespace pic
188 
189 #endif /* PIC_FILTERING_FILTER_ASSEMBLE_HDR_HPP */
190 
float remove(float x, int channel)
remove linearizes a camera value using the inverse CRF.
Definition: camera_response_function.hpp:205
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
HDR_REC_DOMAIN
The HDR_REC_DOMAIN enum HRD_LOG: assembling HDR image in the log-domain.
Definition: filter_assemble_hdr.hpp:38
float delta_value
Definition: filter_assemble_hdr.hpp:49
Definition: filter_assemble_hdr.hpp:38
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
FilterAssembleHDR(CameraResponseFunction *crf=NULL, CRF_WEIGHT weight_type=CW_DEB97, HDR_REC_DOMAIN domain=HRD_LOG)
FilterAssembleHDR.
Definition: filter_assemble_hdr.hpp:162
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
float channelsf
Definition: image.hpp:84
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_assemble_hdr.hpp:57
int y0
Definition: bbox.hpp:32
CRF_WEIGHT weight_type
Definition: filter_assemble_hdr.hpp:48
int minInputImages
Definition: filter_radial_basis_function.hpp:56
The FilterAssembleHDR class.
Definition: filter_assemble_hdr.hpp:43
Definition: filter_assemble_hdr.hpp:38
void update(CameraResponseFunction *crf, CRF_WEIGHT weight_type=CW_DEB97, HDR_REC_DOMAIN domain=HRD_LOG)
update
Definition: filter_assemble_hdr.hpp:177
static T sum(T *data, int size)
sum
Definition: array.hpp:416
Definition: filter_assemble_hdr.hpp:38
The CameraResponseFunction class.
Definition: camera_response_function.hpp:48
Definition: weight_function.hpp:28
HDR_REC_DOMAIN domain
Definition: filter_assemble_hdr.hpp:47
PIC_INLINE float weightFunction(float x, CRF_WEIGHT type)
weightFunction computes weight functions for x in [0,1].
Definition: weight_function.hpp:36
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
Definition: bilateral_separation.hpp:25
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
#define MAX(a, b)
Definition: math.hpp:73
int width
Definition: image.hpp:80
CameraResponseFunction * crf
Definition: filter_assemble_hdr.hpp:46
CRF_WEIGHT
The CRF_WEIGHT enum.
Definition: weight_function.hpp:28