26 #include <hugin_config.h>
30 #include <vigra/impex.hxx>
42 #define snprintf _snprintf
64 for(
char *c = optarg; *c; c++) {
82 std::cerr<<
"Error: unknown option" << std::endl;
91 for(
char *c = optarg; *c; c++) {
100 std::cerr<<
"Error: unknown option" << std::endl;
108 std::cout <<
"deghosting_mask: creates mask for removing ghosting in images" << std::endl
111 <<
"Usage: deghosting_mask [options] inputfile(s) " << std::endl
112 <<
" option are: " << std::endl
113 <<
" -o, --output=PREFIX prefix for output masks" << std::endl
114 <<
" -i, --iterations=ITER number of iterations, default is (ITER > 0)" << std::endl
116 <<
" -s, --sigma=SIGMA standard deviation of Gaussian weighting" << std::endl
117 <<
" function (SIGMA > 0); default: " <<
sigma << std::endl
119 <<
" -t, --threshold=THRESH threshold; default: " <<
thresholdLim << std::endl
120 <<
" -c, --contrast=CONTR change contrast before applying threshold;" << std::endl
121 <<
" default: " <<
contrast << std::endl
122 <<
" -a, --advanced=SET advanced settings. Possible options are:" << std::endl
123 <<
" f use gray images for computation. It's about two times faster" << std::endl
124 <<
" but it usually returns worse results." << std::endl
125 <<
" You also have to change threshold to smaller value (around 100)" << std::endl
126 <<
" g use gamma 2.2 correction instead of logarithm if input images are HDR" << std::endl
127 <<
" m do not scale image, NOTE: slows down process" << std::endl
128 <<
" t use simple threshold, may result in holes in images" << std::endl
129 <<
" w compute \"complete\" weights, not only probabilities" << std::endl
130 <<
" -w, --save=SET advanced save settings" << std::endl
131 <<
" i save initial weights" << std::endl
132 <<
" w save generated weights" << std::endl
133 <<
" -h, --help display this help" << std::endl
134 <<
" -v, --verbose verbose, repeat for more verbose output" << std::endl;
137 int main(
int argc,
char *argv[]) {
140 const char * optstring =
"o:i:s:r:t:c:a:w:hv";
143 std::string outputPrefix =
"weight";
145 enum optionArgumentKind {
166 static struct option longOptions[] = {
167 {
"output", 1, 0, StringArgument },
168 {
"iterations", 1, 0, IntegerArgument },
169 {
"sigma", 1, 0, DoubleArgument },
170 {
"response", 1, 0, ArrayArgument },
171 {
"threshold", 1, 0, DoubleArgument },
172 {
"contrast", 1, 0, DoubleArgument },
173 {
"advanced", 1, 0, StringArgument },
174 {
"save", 1, 0, StringArgument },
175 {
"help", 0, 0, NoArgument },
176 {
"verbose", 0, 0, NoArgument },
191 while ((c = getopt_long(argc, argv, optstring, longOptions, &optionIndex)) != -1) {
194 if (longOptions[optionIndex].flag != 0)
break;
195 switch (optionIndex) {
203 std::cerr <<
"There's a problem with parsing options" << std::endl;
209 case StringArgument: {
210 if (longOptions[optionIndex].flag != 0)
break;
211 switch (optionIndex) {
213 outputPrefix = optarg;
222 std::cerr <<
"There's a problem with parsing options" << std::endl;
228 case IntegerArgument: {
229 if (longOptions[optionIndex].flag != 0)
break;
230 switch (optionIndex) {
235 std::cerr <<
"There's a problem with parsing options" << std::endl;
241 case DoubleArgument: {
242 if (longOptions[optionIndex].flag != 0)
break;
243 switch (optionIndex) {
245 sigma = atof(optarg);
257 case ArrayArgument: {
258 if (longOptions[optionIndex].flag != 0)
break;
259 switch (optionIndex) {
268 outputPrefix = optarg;
274 sigma = atof(optarg);
308 std::cout << std::endl;
310 unsigned nFiles = argc - optind;
318 std::vector<std::string> inputFiles;
319 for (
size_t i = optind; i < (size_t)argc; i++)
321 inputFiles.push_back(argv[i]);
324 std::vector<deghosting::FImagePtr> weights;
325 std::vector<vigra::Rect2D> inputROI;
326 vigra::Rect2D outputROI;
347 for (
unsigned int i = 0; i<weights.size(); ++i)
350 snprintf(tmpfn, 99,
"%s_%u.tif", outputPrefix.c_str(), i);
351 vigra::ImageExportInfo exWeights(tmpfn);
352 exWeights.setPixelType(
"UINT8");
353 exWeights.setPosition(inputROI[i].upperLeft());
354 exWeights.setCanvasSize(vigra::Size2D(inputROI[i].lowerRight().x, inputROI[i].lowerRight().y));
355 vigra::Rect2D roi(inputROI[i]);
356 roi.moveBy(-outputROI.upperLeft());
357 vigra::exportImage(
srcImageRange(*weights[i], roi), exWeights);
362 for (
unsigned int i = 0; i < weights.size(); ++i)
370 for (
unsigned int i = 0; i<weights.size(); ++i)
375 snprintf(tmpfn, 99,
"%s_mask.tif", fileName.c_str());
376 vigra::ImageExportInfo exWeights(tmpfn);
377 exWeights.setPixelType(
"UINT8");
378 exWeights.setPosition(inputROI[i].upperLeft());
379 exWeights.setCanvasSize(vigra::Size2D(inputROI[i].lowerRight().x, inputROI[i].lowerRight().y));
380 vigra::Rect2D roi(inputROI[i]);
381 roi.moveBy(-outputROI.upperLeft());
382 vigra::BImage outImg = vigra::BImage((*thresholded[i]).size());
387 catch (
const std::exception & e)
389 std::cerr <<
"caught exception: " << e.what() << std::endl;
393 std::cerr <<
"caught unknown exception" << std::endl;
const uint16_t ADV_MULTIRES
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
std::vector< vigra::Rect2D > getInputROIs() const
static const uint16_t OTHER_GRAY
virtual std::vector< FImagePtr > createWeightMasks() override
create weight masks create weight masks for masking out ghosting regions
static uint16_t otherThresholdFlags
void simpleDenoise(SrcIterator sy, SrcIterator send, SrcAccessor sa, DestIterator dy, DestAccessor da)
Simple denoising algorithm Copyright (C) 2009 Lukáš Jirkovský l.jirkovsky@gmail.com
static deghosting::EMoR response(0.0f)
std::string stripExtension(const std::string &basename2)
remove extension of a filename
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
static const uint16_t SAVE_GENWEIGHTS
Tool for creating b/w alpha masks to eliminate ghosting artifacts Copyright (C) 2009 Lukáš Jirkovsk...
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
const uint16_t SAVE_INITWEIGHTS
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.
std::vector< float > EMoR
const uint16_t THRESHOLD_DONTCARE
static uint16_t debugFlags
static uint16_t otherFlags
std::string GetHuginVersion()
return a string with version numbers
void parseOptions_save(char *optarg)
function handling save options
void parseOptions_advanced(char *optarg)
function handling advanced options
static double thresholdLim
vigra::Rect2D getOutputROI() const
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
int main(int argc, char *argv[])