27#include <hugin_config.h>
36#include <vigra/error.hxx>
37#include <vigra/functorexpression.hxx>
38#include <vigra/transformimage.hxx>
48#include "../deghosting/deghosting.h"
49#include "../deghosting/khan.h"
67 std::vector<ImagePtr> images;
69 std::vector<vigra::ImageImportInfo>
imageInfo;
72 for (
size_t i = 0;
i < inputFiles.size();
i++)
74 vigra::ImageImportInfo info(inputFiles[
i].
c_str());
78 outputROI = vigra::Rect2D(vigra::Point2D(info.getPosition()), info.size());
82 outputROI |= vigra::Rect2D(vigra::Point2D(info.getPosition()), info.size());
93 std::cout <<
"Loading image: " << inputFiles[
i] << std::endl;
100 weight->resize(img->size().width(), img->size().height(), 0);
103 importImageAlpha(
imageInfo[
i], destImage(*img, offset), destImage(*weight, offset));
108 vigra::initImage(vigra::destImageRange(*weight, vigra::Rect2D(offset,
imageInfo[
i].size())), 255);
110 images.push_back(img);
118 std::cout <<
"Calculating weighted average " << std::endl;
125 for (
int y=0; y <
output.height(); y++)
127 for (
int x=0; x <
output.width(); x++)
132 for (
unsigned imgNr=0; imgNr < images.size(); imgNr++)
135 const vigra::UInt8 weight = (*
weightImages[imgNr])(x, y);
136 waverage( (*images[imgNr])(x,y), weight);
152 const std::vector<deghosting::FImagePtr>& weights,
154 vigra::BImage& alpha,
159 std::cout <<
"Merging input images" << std::endl;
161 int width = (weights[0])->width();
162 int height = (weights[0])->height();
164 assert(inputFiles.size() == weights.size());
166 vigra::BasicImage<vigra::NumericTraits<vigra::FRGBImage::PixelType>::Promote>
weightedImg(width, height);
167 vigra::BasicImage<vigra::NumericTraits<vigra::FImage::PixelType>::Promote>
weightAdded(width, height);
168 for(
unsigned i = 0;
i < inputFiles.size();
i++)
171 vigra::BasicImage<vigra::NumericTraits<vigra::FRGBImage::PixelType>::Promote>
tmpImg(
outputROI.size());
174 vigra::Point2D offset = vigra::Point2D(
inputInfo.getPosition());
187 vigra::combineThreeImages(srcImageRange(
tmpImg), srcImage(*(weights[
i])), srcImage(
weightedImg), destImage(
weightedImg), vigra::functor::Arg1() *vigra::functor::Arg2() + vigra::functor::Arg3());
188 vigra::combineTwoImages(srcImageRange(
weightAdded), srcImage(*(weights[
i])), destImage(
weightAdded), vigra::functor::Arg1() + vigra::functor::Arg2());
190 output.resize(width, height);
191 alpha.resize(width, height, 0);
192 vigra::combineTwoImages(srcImageRange(
weightedImg), srcImage(
weightAdded), destImage(
output), vigra::functor::Arg1() / vigra::functor::Arg2());
193 vigra::transformImage(vigra::srcImageRange(
weightAdded), vigra::destImage(alpha),
194 vigra::Threshold<vigra::FImage::PixelType, vigra::BImage::PixelType>(1e-7f,
FLT_MAX, 0, 255));
200 std::cout << name <<
": merge overlapping images" << std::endl
204 <<
"Usage: " << name <<
" [options] -o output.exr <input-files>" << std::endl
205 <<
"Valid options are:" << std::endl
206 <<
" -o|--output prefix output file" << std::endl
207 <<
" -m mode merge mode, can be one of: avg (default), avg_slow, khan, if avg, no" << std::endl
208 <<
" -i and -s options apply" << std::endl
209 <<
" -i iter number of iterations to execute (default is 4). Khan only" << std::endl
210 <<
" -s sigma standard deviation of Gaussian weighting" << std::endl
211 <<
" function (sigma > 0); default: 30. Khan only" << std::endl
212 <<
" -a set advanced settings. Possible options are:" << std::endl
213 <<
" f use gray images for computation. It's about two times faster" << std::endl
214 <<
" but it usually returns worse results." << std::endl
215 <<
" g use gamma 2.2 correction instead of logarithm" << std::endl
216 <<
" m do not scale image, NOTE: slows down process" << std::endl
217 <<
" -c Only consider pixels that are defined in all images (avg mode only)" << std::endl
218 <<
" -v|--verbose Verbose, print progress messages, repeat for" << std::endl
219 <<
" even more verbose output" << std::endl
220 <<
" -h|help Display help (this text)" << std::endl
229 const char*
optstring =
"chvo:m:i:s:a:el";
241 std::string mode =
"avg";
262 for(
char* c =
optarg; *c; c++)
311 std::cout << std::endl <<
"Only one input image given. Copying input image to output image." << std::endl;
320 std::vector<std::string> inputFiles;
323 inputFiles.push_back(
argv[
i]);
330 if (mode ==
"avg_slow")
336 std::cout <<
"Running simple weighted avg algorithm" << std::endl;
344 std::cout <<
"Writing " <<
outputFile << std::endl;
347 exinfo.setPixelType(
"FLOAT");
352 else if (mode ==
"avg")
360 else if (mode ==
"khan")
364 std::cout <<
"Running Khan deghosting algorithm" << std::endl;
367 std::vector<deghosting::FImagePtr> weights;
385 std::cout <<
"Writing " <<
outputFile << std::endl;
388 exinfo.setPixelType(
"FLOAT");
395 std::cerr <<
"Unknown merge mode, see help for a list of possible modes" << std::endl;
399 catch (std::exception& e)
401 std::cerr <<
"caught exception: " << e.what() << std::endl;
void reduceFilesToHDR(std::vector< std::string > input, std::string output, bool onlyCompleteOverlap, Functor &reduce)
static uint16_t otherFlags
class AlphaIterator class AlphaAccessor inline void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
class AlphaIterator class AlphaAccessor inline void exportImageAlpha(ImageIterator image_upper_left, ImageIterator image_lower_right, ImageAccessor image_accessor, AlphaIterator alpha_upper_left, AlphaAccessor alpha_accessor, const ImageExportInfo &export_info)
int main(int argc, char *argv[])
vigra::FRGBImage ImageType
std::shared_ptr< ImageType > ImagePtr
bool mergeWeightedAverage(std::vector< std::string > inputFiles, vigra::FRGBImage &output, vigra::BImage &alpha, vigra::Rect2D &outputROI)
const uint16_t OTHER_GRAY
bool weightedAverageOfImageFiles(const std::vector< std::string > &inputFiles, const std::vector< deghosting::FImagePtr > &weights, vigra::FRGBImage &output, vigra::BImage &alpha, const vigra::Rect2D outputROI)
compute output image when given source images
const uint16_t ADV_MULTIRES
std::shared_ptr< vigra::BImage > BImagePtr
std::string GetHuginVersion()
return a string with version numbers
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.