#include "haader.h" #include #include #include #include #include #include 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 << " ...\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, 1000); { fstream s; s.open("irf.csv", std::ios::out); irf.to_csv_stream(s); } 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); { fstream s; s.open("rf.csv", std::ios::out); rf.to_csv_stream(s); } { haader::Image x = hdr_img.expose(0.001, rf, 1.0); x.save_as_ppm_file("test_1000.ppm"); } { haader::Image x = hdr_img.expose(1.0 / 1024.0, rf, 1.0); x.save_as_ppm_file("test_1024.ppm"); } // 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; }