Stitcher.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00030 #include "Stitcher.h"
00031 
00032 #include <vigra/stdimage.hxx>
00033 
00034 namespace HuginBase {
00035 namespace Nona {
00036 
00037 using namespace std;
00038 using namespace vigra;
00039 using namespace vigra_ext;
00040 
00048 void stitchPanorama(const PanoramaData & pano,
00049                         const PanoramaOptions & opt,
00050                         AppBase::ProgressDisplay* progress,
00051                         const std::string & basename,
00052                         const UIntSet & usedImgs,
00053                         const AdvancedOptions& advOptions)
00054 {
00055     DEBUG_ASSERT(pano.getNrOfImages() > 0);
00056 
00057     // probe the first image to determine a suitable image type for stitching
00058     unsigned int imgNr = *(usedImgs.begin());
00059     string fname =  pano.getImage(imgNr).getFilename().c_str();
00060     DEBUG_DEBUG("Probing image: " << fname);
00061     vigra::ImageImportInfo info(fname.c_str());
00062     std::string pixelType = info.getPixelType();
00063     int bands = info.numBands();
00064     int extraBands = info.numExtraBands();
00065 
00066     // check if all other relevant images have the same type
00067     for (UIntSet::const_iterator it = usedImgs.begin()++; it != usedImgs.end(); ++it) {
00068         vigra::ImageImportInfo info2(pano.getImage(*it).getFilename().c_str());
00069         if ( pixelType != info2.getPixelType() ) {
00070             UTILS_THROW(std::runtime_error, "image " <<
00071                     pano.getImage(*it).getFilename() << " uses " <<
00072                     info2.getPixelType() << " valued pixel, while " <<
00073                     pano.getImage(0).getFilename() << " uses: " << pixelType);
00074             return;
00075         }
00076 
00077         if (info2.numBands() - info2.numExtraBands() != bands - extraBands) {
00078             UTILS_THROW(std::runtime_error, "image " <<
00079                     pano.getImage(*it).getFilename() << " has " <<
00080                     info2.numBands() << " channels, while " <<
00081                     pano.getImage(0).getFilename() << " uses: " << bands);
00082             return;
00083         }
00084     }
00085 //    DEBUG_DEBUG("Output pixel type: " << pixelType);
00086     PanoramaOptions opts = opt;
00087     if (opts.outputMode == PanoramaOptions::OUTPUT_HDR) {
00088         if (opts.outputPixelType.size() == 0) {
00089             opts.outputPixelType = "FLOAT";
00090         }
00091     } else {
00092         // get the emor parameters.
00093         opts.outputEMoRParams = pano.getSrcImage(0).getEMoRParams();
00094         if (opts.outputPixelType.size() == 0) {
00095             opts.outputPixelType = pixelType;
00096         } else {
00097             // if output format is specified, use output format as stitching format
00098             // TODO: this will fail when going down in precision: UINT16 -> UINT8
00099             pixelType = opts.outputPixelType;
00100         }
00101     }
00102 
00103 #if 1
00104     if (opts.outputMode == PanoramaOptions::OUTPUT_HDR) {
00105         if (bands == 1 || bands == 2 && extraBands == 1) {
00106             stitchPanoIntern<FImage,BImage>(pano, opts, progress, basename, usedImgs, advOptions);
00107         } else if (bands == 3 || bands == 4 && extraBands == 1) {
00108             stitchPanoIntern<FRGBImage,BImage>(pano, opts, progress, basename, usedImgs, advOptions);
00109         } else {
00110             DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
00111             throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
00112         }
00113     } else {
00114         // stitch the pano with a suitable image type
00115         if (bands == 1 || bands == 2 && extraBands == 1) {
00116             if (pixelType ==  "UINT8"||
00117                 pixelType == "INT16" ||
00118                 pixelType == "UINT16" )
00119             {
00120                 stitchPanoGray_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00121             } else {
00122                 stitchPanoGray_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00123             }
00124         } else if (bands == 3 || bands == 4 && extraBands == 1) {
00125             if (pixelType == "UINT8" ||
00126                 pixelType == "INT16" ||
00127                 pixelType == "UINT16" )
00128             {
00129                 stitchPanoRGB_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00130             } else {
00131                 stitchPanoRGB_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00132             }
00133         }
00134     }
00135 #else
00136     // always stitch with float images.
00137     if (bands == 1 || bands == 2 && extraBands == 1) {
00138         stitchPanoIntern<FImage,BImage>(pano, opts, progress, basename, usedImgs);
00139     } else if (bands == 3 || bands == 4 && extraBands == 1) {
00140         stitchPanoIntern<FRGBImage,BImage>(pano, opts, progress, basename, usedImgs);
00141     } else {
00142         DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
00143         throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
00144         return;
00145     }
00146 #endif
00147 }
00148 
00149 
00150 } // namespace
00151 } // namespace
00152 

Generated on 3 Sep 2015 for Hugintrunk by  doxygen 1.4.7