1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <QString>
#include <iostream>
#include <vector>
#include <boost/program_options.hpp>
#include <boost/algorithm/minmax_element.hpp>
#include <Libpfs/utils/msec_timer.h>
#include <Libpfs/io/framewriterfactory.h>
#include <Libpfs/io/framereaderfactory.h>
#include <HdrCreation/fusionoperator.h>
#include <Exif/ExifOperations.h>
#include <Libpfs/colorspace/rgbremapper_fwd.h>
using namespace std;
using namespace pfs;
using namespace pfs::io;
using namespace libhdr;
using namespace libhdr::fusion;
namespace po = boost::program_options;
libhdr::fusion::FrameEnhanced loadFile(const std::string& filename)
{
FrameReaderPtr reader = FrameReaderFactory::open(filename);
FramePtr image(new Frame);
reader->read(*image, pfs::Params());
float averageLuminace = ExifOperations::getAverageLuminance(filename);
std::cout << filename << " avg luminance = " << averageLuminace << std::endl;
return libhdr::fusion::FrameEnhanced(image, averageLuminace);
}
int main(int argc, char** argv)
{
#ifdef LHDR_CXX11_ENABLED
string responseCurveStr;
string weightFunctionStr;
string fusionModelStr;
string outputFile;
vector<string> inputFiles;
// program options
po::options_description desc("Allowed options: ");
desc.add_options()
("response-type,r", po::value<std::string>(&responseCurveStr)->default_value("srgb"), "response curve type")
("weight-type,w", po::value<std::string>(&weightFunctionStr)->default_value("flat"), "weighting function type")
("fusion-type,f", po::value<std::string>(&fusionModelStr)->default_value("debevec"), "fusion algorithm")
("output-file,o", po::value<std::string>(&outputFile)->required(), "output file")
("input-files,i", po::value< vector<string> >(&inputFiles)->required(), "input files (JPEG, TIFF or RAW)")
;
try
{
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).allow_unregistered().run(), vm);
po::notify(vm);
std::vector<libhdr::fusion::FrameEnhanced> images;
foreach (const string& filename, inputFiles)
{
images.push_back(loadFile(filename));
}
cout << "Are you ready?\n";
char c;
cin >> c;
msec_timer t;
t.start();
ResponseCurve responseCurve(ResponseCurve::fromString(responseCurveStr));
WeightFunction weightFunction(WeightFunction::fromString(weightFunctionStr));
// responseCurve.readFromFile("responses_before.m");
FusionOperatorPtr fusionOperator = IFusionOperator::build(IFusionOperator::fromString(fusionModelStr));
cout << responseCurveStr << " (" << responseCurve.getType() << ") / "
<< weightFunctionStr << " (" << weightFunction.getType() << ") / "
<< fusionModelStr << "(" << fusionOperator->getType() << ")"
<< std::endl;
pfs::FramePtr newHdr(fusionOperator->computeFusion(responseCurve, weightFunction, images));
if ( newHdr == NULL )
{
return -1;
}
responseCurve.writeToFile("responses_before.m");
responseCurve.writeToFile("responses_after.m");
t.stop_and_update();
std::cout << "Fusion elapsed time: " << t.get_time() << std::endl;
Channel* red;
Channel* green;
Channel* blue;
newHdr->getXYZChannels(red, green, blue);
pair<Channel::iterator, Channel::iterator> outRed =
boost::minmax_element(red->begin(), red->end());
cout << "Red: (" << *outRed.first << ", " << *outRed.second << ")" << endl;
pair<Channel::iterator, Channel::iterator> outGreen =
boost::minmax_element(green->begin(), green->end());
cout << "Green: (" << *outGreen.first << ", " << *outGreen.second << ")" << endl;
pair<Channel::iterator, Channel::iterator> outBlue =
boost::minmax_element(blue->begin(), blue->end());
cout << "Blue: (" << *outBlue.first << ", " << *outBlue.second << ")" << endl;
float min = std::min(*outRed.first,
std::min(*outGreen.first, *outBlue.first));
float max = std::max(*outRed.second,
std::max(*outGreen.second, *outBlue.second));
cout << "Min/Max: " << min << ", " << max << std::endl;
FrameWriterPtr writer = FrameWriterFactory::open(outputFile, pfs::Params());
writer->write(*newHdr,
pfs::Params("mapping_method", MAP_GAMMA2_6)
("min_luminance", min)
("max_luminance", max));
return 0;
}
catch (std::exception& ex)
{
cout << ex.what() << "\n";
cout << desc << "\n";
return -1;
}
#else
cout << "This code doens't work without a C++11 compiler! \n";
return -1;
#endif
}
|