Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stitcher.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
26 #include "Stitcher.h"
27 
28 #include <vigra/stdimage.hxx>
29 
30 namespace HuginBase {
31 namespace Nona {
32 
40 void stitchPanorama(const PanoramaData & pano,
41  const PanoramaOptions & opt,
42  AppBase::ProgressDisplay* progress,
43  const std::string & basename,
44  const UIntSet & usedImgs,
45  const AdvancedOptions& advOptions)
46 {
47  DEBUG_ASSERT(pano.getNrOfImages() > 0);
48 
49  // probe the first image to determine a suitable image type for stitching
50  unsigned int imgNr = *(usedImgs.begin());
51  std::string fname = pano.getImage(imgNr).getFilename().c_str();
52  DEBUG_DEBUG("Probing image: " << fname);
53  vigra::ImageImportInfo info(fname.c_str());
54  std::string pixelType = info.getPixelType();
55  int bands = info.numBands();
56  int extraBands = info.numExtraBands();
57 
58  // check if all other relevant images have the same type
59  for (UIntSet::const_iterator it = usedImgs.begin()++; it != usedImgs.end(); ++it) {
60  vigra::ImageImportInfo info2(pano.getImage(*it).getFilename().c_str());
61  if ( pixelType != info2.getPixelType() ) {
62  UTILS_THROW(std::runtime_error, "image " <<
63  pano.getImage(*it).getFilename() << " uses " <<
64  info2.getPixelType() << " valued pixel, while " <<
65  pano.getImage(0).getFilename() << " uses: " << pixelType);
66  return;
67  }
68 
69  if (info2.numBands() - info2.numExtraBands() != bands - extraBands) {
70  UTILS_THROW(std::runtime_error, "image " <<
71  pano.getImage(*it).getFilename() << " has " <<
72  info2.numBands() << " channels, while " <<
73  pano.getImage(0).getFilename() << " uses: " << bands);
74  return;
75  }
76  }
77 // DEBUG_DEBUG("Output pixel type: " << pixelType);
78  PanoramaOptions opts = opt;
80  if (opts.outputPixelType.empty()) {
81  opts.outputPixelType = "FLOAT";
82  }
83  } else {
84  if (pano.getImage(0).getResponseType() == HuginBase::BaseSrcPanoImage::RESPONSE_EMOR)
85  {
86  // get the emor parameters.
87  opts.outputEMoRParams = pano.getSrcImage(0).getEMoRParams();
88  }
89  else
90  {
91  // clear the parameters to indicatate these should not be used
92  opts.outputEMoRParams.clear();
93  };
94  if (opts.outputPixelType.empty()) {
95  opts.outputPixelType = pixelType;
96  } else {
97  // if output format is specified, use output format as stitching format
98  // TODO: this will fail when going down in precision: UINT16 -> UINT8
99  pixelType = opts.outputPixelType;
100  }
101  }
102 
103 #if 1
105  if (bands == 1 || (bands == 2 && extraBands == 1)) {
106  stitchPanoIntern<vigra::FImage, vigra::BImage>(pano, opts, progress, basename, usedImgs, advOptions);
107  } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
108  stitchPanoIntern<vigra::FRGBImage, vigra::BImage>(pano, opts, progress, basename, usedImgs, advOptions);
109  } else {
110  DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
111  throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
112  }
113  } else {
114  // stitch the pano with a suitable image type
115  if (bands == 1 || (bands == 2 && extraBands == 1)) {
116  if (pixelType == "UINT8"||
117  pixelType == "INT16" ||
118  pixelType == "UINT16" )
119  {
120  stitchPanoGray_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
121  } else {
122  stitchPanoGray_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
123  }
124  } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
125  if (pixelType == "UINT8" ||
126  pixelType == "INT16" ||
127  pixelType == "UINT16" )
128  {
129  stitchPanoRGB_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
130  } else {
131  stitchPanoRGB_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
132  }
133  }
134  }
135 #else
136  // always stitch with float images.
137  if (bands == 1 || (bands == 2 && extraBands == 1)) {
138  stitchPanoIntern<FImage,BImage>(pano, opts, progress, basename, usedImgs);
139  } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
140  stitchPanoIntern<FRGBImage,BImage>(pano, opts, progress, basename, usedImgs);
141  } else {
142  DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
143  throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
144  return;
145  }
146 #endif
147 }
148 
149 
150 } // namespace
151 } // namespace
152 
std::vector< float > outputEMoRParams
void stitchPanoRGB_8_16(const PanoramaData &pano, const PanoramaOptions &opts, AppBase::ProgressDisplay *progress, const std::string &basename, const UIntSet &usedImgs, const char *pixelType, const AdvancedOptions &advOptions)
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
void stitchPanoGray_8_16(const PanoramaData &pano, const PanoramaOptions &opts, AppBase::ProgressDisplay *progress, const std::string &basename, const UIntSet &usedImgs, const char *pixelType, const AdvancedOptions &advOptions)
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
#define UTILS_THROW(class, msg)
Definition: utils.h:83
empirical model of response
Definition: SrcPanoImage.h:100
Model for a panorama.
Definition: PanoramaData.h:81
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
void stitchPanorama(const PanoramaData &pano, const PanoramaOptions &opt, AppBase::ProgressDisplay *progress, const std::string &basename, const UIntSet &usedImgs, const AdvancedOptions &advOptions)
The main stitching function.
Definition: Stitcher.cpp:40
#define DEBUG_ERROR(msg)
Definition: utils.h:76
void stitchPanoGray_32_float(const PanoramaData &pano, const PanoramaOptions &opts, AppBase::ProgressDisplay *progress, const std::string &basename, const UIntSet &usedImgs, const char *pixelType, const AdvancedOptions &advOptions)
Contains various routines used for stitching panoramas.
void stitchPanoRGB_32_float(const PanoramaData &pano, const PanoramaOptions &opts, AppBase::ProgressDisplay *progress, const std::string &basename, const UIntSet &usedImgs, const char *pixelType, const AdvancedOptions &advOptions)
#define DEBUG_DEBUG(msg)
Definition: utils.h:68
std::map< std::string, std::string > AdvancedOptions
static void info(const char *fmt,...)
Definition: svm.cpp:95
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual std::size_t getNrOfImages() const =0
number of images.
Panorama image options.