| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "haader.h"
-
- #include <time.h>
- #include <math.h>
-
- #include <iostream>
- #include <sstream>
- #include <iomanip>
-
- using namespace std;
-
-
- void print_usage(const char *argv_0) {
- cout << "Construct an HDR-image from a series of photographs\n";
- cout << "with different exposure times and then synthesize\n";
- cout << "new images from it.\n\n";
- cout << "Usage:\n";
- cout << argv_0 << " <image_path_1> <image_path_2> ...\n\n";
- }
-
- int main(int argc, char *argv[])
- {
- if (argc >= 2) {
- haader::HdrImageStack stack;
-
- // read image files.
- bool ok = stack.read_from_files(argv + 1, argc - 1);
-
- if (ok) {
- clock_t start = clock();
-
- // construct and save average image
- {
- haader::Image img;
- stack.get_average_image(img);
- img.save_as_ppm_file("average.ppm");
- }
-
- // approximate inverse response function
- haader::InverseResponseFunction irf;
- bool irf_ok = stack.get_inverse_response_function(irf, 2000);
-
- if (irf_ok) {
- haader::HdrImage hdr_img;
- hdr_img = stack.get_hdr_image(irf);
-
- // save logarithmic image of scene luminance values
- {
- haader::Image x = hdr_img.get_log_image();
- x.save_as_ppm_file("log_image.ppm");
- }
-
- // convert irf to response function
- haader::ResponseFunction rf;
- rf = irf.to_response_function(1024);
-
- // create images by a simulated exposure of the HDR image with the response function
- cout << "Expose..." << endl;
- for (int i = 0; i < 20; i++) {
- // exposure time
- double t = pow(2.0, (double)i * (-12.0 / 20.0));
-
- // create image
- haader::Image x = hdr_img.expose(t, rf, 1.0);
-
- // save image
- stringstream ss;
- ss << "expose_" << setw(5) << setfill('0') << i << ".ppm";
- string path = ss.str();
- x.save_as_ppm_file(path.c_str());
-
- cout << "\nexposure time: " << t << " sec" << endl;
- cout << "save as " << path << endl;
- }
- }
- clock_t end = clock();
- double seconds = (end - start) / (double)CLOCKS_PER_SEC;
- cout << "\nsecs: " << seconds << endl;
- }
- } else {
- print_usage(argv[0]);
- }
-
- return 0;
- }
|