Hugin trunk 0.1
Loading...
Searching...
No Matches
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
30namespace HuginBase {
31namespace Nona {
32
40void stitchPanorama(const PanoramaData & pano,
41 const PanoramaOptions & opt,
43 const std::string & basename,
44 const UIntSet & usedImgs,
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()) {
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
100 }
101 }
102
103#if 1
105 if (bands == 1 || (bands == 2 && extraBands == 1)) {
107 } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
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)) {
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
Contains various routines used for stitching panoramas.
@ RESPONSE_EMOR
empirical model of response
Model for a panorama.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
virtual std::size_t getNrOfImages() const =0
number of images.
Panorama image options.
std::vector< float > outputEMoRParams
#define DEBUG_ERROR(msg)
Definition utils.h:76
#define DEBUG_ASSERT(cond)
Definition utils.h:80
#define DEBUG_DEBUG(msg)
Definition utils.h:68
#define UTILS_THROW(class, msg)
Definition utils.h:83
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)
Definition Stitcher4.cpp:34
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)
Definition Stitcher1.cpp:28
std::map< std::string, std::string > AdvancedOptions
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
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)
Definition Stitcher3.cpp:28
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)
Definition Stitcher2.cpp:28
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::set< unsigned int > UIntSet
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.
Definition threshold.h:41