PICCANTE  0.4
The hottest HDR imaging library!
hdr_merger.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_ALGORITHMS_HDR_MERGER_HPP
19 #define PIC_ALGORITHMS_HDR_MERGER_HPP
20 
21 #include <vector>
22 #include <string>
23 
24 #include "../base.hpp"
25 #include "../util/vec.hpp"
26 #include "../algorithms.hpp"
27 #include "../algorithms/camera_response_function.hpp"
28 #include "../features_matching/ward_alignment.hpp"
29 #include "../filtering/filter_assemble_hdr.hpp"
30 
31 namespace pic {
32 
34 
35 class HDRMerger
36 {
37 protected:
41 
44 
45  std::vector<std::string> file_name_vec;
46  std::vector<float> exposure_time_vec;
47 
53  void incrementalAlignment(ImageVec &stack, std::vector<Vec2i> &s_vec)
54  {
55  int n = int(stack.size());
56 
57  for(int i = 0; i < (n - 1); i++) {
58  Vec2i s_i = WardAlignment::execute(stack[i + 1], stack[i]);
59  s_vec.push_back(s_i);
60  }
61 
62  int n2 = int(s_vec.size());
63  for(int i = 0; i < (n2 - 1); i++) {
64  Vec2i n_i = s_vec[i];
65 
66  for(int j = (i + 1); j < n2; j++) {
67  n_i += s_vec[j];
68  }
69 
70  s_vec[i] = n_i;
71  }
72  }
73 
74 public:
75 
80  {
81  domain = HRD_LOG;
82  weight = CW_DEB97;
83  hdra = HA_NONE;
84 
85  crf = NULL;
86  }
87 
89  {
90  release();
91  }
92 
96  void release()
97  {
98  }
99 
107  HDRAlign hdra,
108  CameraResponseFunction *crf = NULL)
109  {
110  this->hdra = hdra;
111  this->weight = weight;
112  this->domain = domain;
113  this->crf = crf;
114  }
115 
121  void addFile(std::string file_name, float exposure_time = -1.0f)
122  {
123  file_name_vec.push_back(file_name);
124  exposure_time_vec.push_back(exposure_time);
125  }
126 
132  Image *execute(Image *imgOut = NULL)
133  {
134  ImageVec stack;
135 
136  bool bValid = true;
137  int n = int(file_name_vec.size());
138 
139  for(int i = 0; i < n; i++) {
140  Image *img = new Image();
141  img->Read(file_name_vec[i], LT_NOR);
142  stack.push_back(img);
143  bValid = bValid && img->isValid();
144  }
145 
146  if(!bValid) {
147  return imgOut;
148  }
149 
150  ImageVec stack_aligned;
151  ImageVec stack_aligned_track;
152 
153  //align images
154  if(hdra != HA_NONE && (n > 1)) {
155 
156 
158 
159  if(hdra == HA_MTB) {
160  std::vector<Vec2i> shifts;
161  incrementalAlignment(stack, shifts);
162 
163  stack_aligned.push_back(stack[n - 1]);
164 
165  for(int i = 0; i < int(shifts.size()); i++) {
166  auto s_i = shifts[i];
167  if(s_i[0] == 0 && s_i[1] == 0) {
168  stack_aligned.push_back(stack[i]);
169  } else {
170  auto tmp_i = WardAlignment::shiftImage(stack[i], shifts[i], NULL);
171  stack_aligned.push_back(tmp_i);
172  stack_aligned_track.push_back(tmp_i);
173  }
174  }
175  }
176  }
177 
178  //compute CRF
179  if(crf == NULL) {
180  crf = new CameraResponseFunction();
181  crf->DebevecMalik(stack, weight, 256, 20.0f);
182  }
183 
184  //merge all exposure images
186 
187  if(hdra != HA_NONE) {
188  imgOut = merger.Process(stack_aligned, imgOut);
189  } else {
190  imgOut = merger.Process(stack, imgOut);
191  }
192 
193  stdVectorClear(stack);
194  stdVectorClear(stack_aligned_track);
195 
196  return imgOut;
197  }
198 };
199 
200 } // end namespace pic
201 
202 #endif /* PIC_ALGORITHMS_WEIGHT_FUNCTION_HPP */
203 
static Vec2i execute(Image *imgTarget, Image *imgSource)
Definition: ward_alignment.hpp:266
void addFile(std::string file_name, float exposure_time=-1.0f)
addFile
Definition: hdr_merger.hpp:121
CRF_WEIGHT weight
Definition: hdr_merger.hpp:42
HDR_REC_DOMAIN
The HDR_REC_DOMAIN enum HRD_LOG: assembling HDR image in the log-domain.
Definition: filter_assemble_hdr.hpp:38
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
void release()
release
Definition: hdr_merger.hpp:96
void update(CRF_WEIGHT weight, HDR_REC_DOMAIN domain, HDRAlign hdra, CameraResponseFunction *crf=NULL)
update
Definition: hdr_merger.hpp:106
FilterAssembleHDR merger
Definition: hdr_merger.hpp:39
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
Definition: hdr_merger.hpp:33
Definition: hdr_merger.hpp:35
std::vector< std::string > file_name_vec
Definition: hdr_merger.hpp:45
~HDRMerger()
Definition: hdr_merger.hpp:88
Image * execute(Image *imgOut=NULL)
execute
Definition: hdr_merger.hpp:132
void DebevecMalik(ImageVec stack, CRF_WEIGHT type=CW_DEB97, int nSamples=256, float lambda=20.0f)
DebevecMalik computes the CRF of a camera using multiple exposures value following Debevec and Malik ...
Definition: camera_response_function.hpp:392
HDRAlign hdra
Definition: hdr_merger.hpp:40
CameraResponseFunction * crf
Definition: hdr_merger.hpp:38
The FilterAssembleHDR class.
Definition: filter_assemble_hdr.hpp:43
void update(CameraResponseFunction *crf, CRF_WEIGHT weight_type=CW_DEB97, HDR_REC_DOMAIN domain=HRD_LOG)
update
Definition: filter_assemble_hdr.hpp:177
Definition: filter_assemble_hdr.hpp:38
Definition: hdr_merger.hpp:33
Definition: dynamic_range.hpp:29
The CameraResponseFunction class.
Definition: camera_response_function.hpp:48
Definition: weight_function.hpp:28
PIC_INLINE void ImaveVecSortByExposureTime(ImageVec &stack)
ImaveVecSortByExposureTime.
Definition: image_vec.hpp:96
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
std::vector< float > exposure_time_vec
Definition: hdr_merger.hpp:46
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
HDRAlign
Definition: hdr_merger.hpp:33
bool Read(std::string nameFile, LDR_type typeLoad)
Read opens an Image from a file on the disk.
HDR_REC_DOMAIN domain
Definition: hdr_merger.hpp:43
static Image * shiftImage(Image *img, Vec2i shift, Image *ret=NULL)
Definition: ward_alignment.hpp:284
HDRMerger()
HDRMerger.
Definition: hdr_merger.hpp:79
Definition: hdr_merger.hpp:33
The Vec class.
Definition: vec.hpp:35
CRF_WEIGHT
The CRF_WEIGHT enum.
Definition: weight_function.hpp:28
void incrementalAlignment(ImageVec &stack, std::vector< Vec2i > &s_vec)
incrementalAlignment
Definition: hdr_merger.hpp:53
void stdVectorClear(std::vector< T *> &vec)
stdVectorClear
Definition: std_util.hpp:50