A tool to construct HDR-images from a series of exposures.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "haader.h"
  2. #include <time.h>
  3. #include <math.h>
  4. #include <iostream>
  5. #include <sstream>
  6. #include <iomanip>
  7. using namespace std;
  8. void print_usage(const char *argv_0) {
  9. cout << "Construct an HDR-image from a series of photographs\n";
  10. cout << "with different exposure times and then synthesize\n";
  11. cout << "new images from it.\n\n";
  12. cout << "Usage:\n";
  13. cout << argv_0 << " <image_path_1> <image_path_2> ...\n\n";
  14. }
  15. int main(int argc, char *argv[])
  16. {
  17. if (argc >= 2) {
  18. haader::HdrImageStack stack;
  19. // read image files.
  20. bool ok = stack.read_from_files(argv + 1, argc - 1);
  21. if (ok) {
  22. clock_t start = clock();
  23. // construct and save average image
  24. {
  25. haader::Image img;
  26. stack.get_average_image(img);
  27. img.save_as_ppm_file("average.ppm");
  28. }
  29. // approximate inverse response function
  30. haader::InverseResponseFunction irf;
  31. bool irf_ok = stack.get_inverse_response_function(irf, 2000);
  32. if (irf_ok) {
  33. haader::HdrImage hdr_img;
  34. hdr_img = stack.get_hdr_image(irf);
  35. // save logarithmic image of scene luminance values
  36. {
  37. haader::Image x = hdr_img.get_log_image();
  38. x.save_as_ppm_file("log_image.ppm");
  39. }
  40. // convert irf to response function
  41. haader::ResponseFunction rf;
  42. rf = irf.to_response_function(1024);
  43. // create images by a simulated exposure of the HDR image with the response function
  44. cout << "Expose..." << endl;
  45. for (int i = 0; i < 20; i++) {
  46. // exposure time
  47. double t = pow(2.0, (double)i * (-12.0 / 20.0));
  48. // create image
  49. haader::Image x = hdr_img.expose(t, rf, 1.0);
  50. // save image
  51. stringstream ss;
  52. ss << "expose_" << setw(5) << setfill('0') << i << ".ppm";
  53. string path = ss.str();
  54. x.save_as_ppm_file(path.c_str());
  55. cout << "\nexposure time: " << t << " sec" << endl;
  56. cout << "save as " << path << endl;
  57. }
  58. }
  59. clock_t end = clock();
  60. double seconds = (end - start) / (double)CLOCKS_PER_SEC;
  61. cout << "\nsecs: " << seconds << endl;
  62. }
  63. } else {
  64. print_usage(argv[0]);
  65. }
  66. return 0;
  67. }