|
|
@@ -8,6 +8,9 @@
|
|
8
|
8
|
|
|
9
|
9
|
#include "haader.h"
|
|
10
|
10
|
|
|
|
11
|
+#define max_number(a, b) (a) > (b) ? (a) : (b)
|
|
|
12
|
+#define min_number(a, b) (a) < (b) ? (a) : (b)
|
|
|
13
|
+
|
|
11
|
14
|
using namespace std;
|
|
12
|
15
|
using namespace haader;
|
|
13
|
16
|
|
|
|
@@ -262,6 +265,41 @@ Image HdrImage::expose(double exposure_time, const ResponseFunction &rf, double
|
|
262
|
265
|
return output;
|
|
263
|
266
|
}
|
|
264
|
267
|
|
|
|
268
|
+Histogram HdrImage::histogram(unsigned int number_of_bins) const {
|
|
|
269
|
+ Histogram hist;
|
|
|
270
|
+
|
|
|
271
|
+ hist.m_bins.resize(number_of_bins, 0);
|
|
|
272
|
+
|
|
|
273
|
+ if (m_image_data.size() == 0) {
|
|
|
274
|
+ return hist;
|
|
|
275
|
+ }
|
|
|
276
|
+
|
|
|
277
|
+ hist.m_min_value = m_image_data[0];
|
|
|
278
|
+ hist.m_max_value = m_image_data[0];
|
|
|
279
|
+
|
|
|
280
|
+ for (unsigned int i = 0; i < m_image_data.size(); i++) {
|
|
|
281
|
+ double val = m_image_data[i];
|
|
|
282
|
+ hist.m_min_value = min_number(hist.m_min_value, val);
|
|
|
283
|
+ hist.m_max_value = max_number(hist.m_max_value, val);
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
|
286
|
+ double scale = (double)number_of_bins / (hist.m_max_value - hist.m_min_value);
|
|
|
287
|
+
|
|
|
288
|
+ for (unsigned int i = 0; i < m_image_data.size(); i++) {
|
|
|
289
|
+ double val = m_image_data[i];
|
|
|
290
|
+ int bin = (val - hist.m_min_value) * scale;
|
|
|
291
|
+ bin = bin < 0 ? 0 : (bin >= (int)number_of_bins ? (number_of_bins - 1) : bin);
|
|
|
292
|
+ hist.m_bins[bin]++;
|
|
|
293
|
+ }
|
|
|
294
|
+
|
|
|
295
|
+ hist.m_max_freq = 0;
|
|
|
296
|
+ for (unsigned int i = 0; i < number_of_bins; i++) {
|
|
|
297
|
+ hist.m_max_freq = max_number(hist.m_max_freq, hist.m_bins[i]);
|
|
|
298
|
+ }
|
|
|
299
|
+
|
|
|
300
|
+ return hist;
|
|
|
301
|
+}
|
|
|
302
|
+
|
|
265
|
303
|
|
|
266
|
304
|
HdrImageStack::HdrImageStack() {
|
|
267
|
305
|
}
|
|
|
@@ -283,6 +321,7 @@ bool HdrImageStack::read_from_files(char * const* file_paths, int number_of_path
|
|
283
|
321
|
<< file_paths[i]
|
|
284
|
322
|
<< "\")"
|
|
285
|
323
|
<< endl;
|
|
|
324
|
+ m_images.clear();
|
|
286
|
325
|
return false;
|
|
287
|
326
|
}
|
|
288
|
327
|
if (m_images[i].get_exposure_time() == 0.0) {
|
|
|
@@ -290,9 +329,11 @@ bool HdrImageStack::read_from_files(char * const* file_paths, int number_of_path
|
|
290
|
329
|
<< file_paths[i]
|
|
291
|
330
|
<< "\")"
|
|
292
|
331
|
<< endl;
|
|
|
332
|
+ m_images.clear();
|
|
293
|
333
|
return false;
|
|
294
|
334
|
}
|
|
295
|
335
|
} else {
|
|
|
336
|
+ m_images.clear();
|
|
296
|
337
|
return false;
|
|
297
|
338
|
}
|
|
298
|
339
|
}
|
|
|
@@ -475,18 +516,7 @@ bool HdrImageStack::get_inverse_response_function(InverseResponseFunction &outpu
|
|
475
|
516
|
}
|
|
476
|
517
|
}
|
|
477
|
518
|
|
|
478
|
|
- if (output.repair()) {
|
|
479
|
|
- cout << "Inverse response function" << endl;
|
|
480
|
|
- cout << endl;
|
|
481
|
|
- for (unsigned int i = 0; i < 256; i++) {
|
|
482
|
|
- cout << i << "," << output.m_lookup_table[i] << endl;
|
|
483
|
|
- }
|
|
484
|
|
- cout << endl;
|
|
485
|
|
-
|
|
486
|
|
- return true;
|
|
487
|
|
- } else {
|
|
488
|
|
- return false;
|
|
489
|
|
- }
|
|
|
519
|
+ return output.repair();
|
|
490
|
520
|
}
|
|
491
|
521
|
|
|
492
|
522
|
HdrImage HdrImageStack::get_hdr_image(const InverseResponseFunction &invRespFunc) {
|