Stitcher.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #include "Stitcher.h"
00027 
00028 #include <vigra/stdimage.hxx>
00029 
00030 namespace HuginBase {
00031 namespace Nona {
00032 
00040 void stitchPanorama(const PanoramaData & pano,
00041                         const PanoramaOptions & opt,
00042                         AppBase::ProgressDisplay* progress,
00043                         const std::string & basename,
00044                         const UIntSet & usedImgs,
00045                         const AdvancedOptions& advOptions)
00046 {
00047     DEBUG_ASSERT(pano.getNrOfImages() > 0);
00048 
00049     // probe the first image to determine a suitable image type for stitching
00050     unsigned int imgNr = *(usedImgs.begin());
00051     std::string fname =  pano.getImage(imgNr).getFilename().c_str();
00052     DEBUG_DEBUG("Probing image: " << fname);
00053     vigra::ImageImportInfo info(fname.c_str());
00054     std::string pixelType = info.getPixelType();
00055     int bands = info.numBands();
00056     int extraBands = info.numExtraBands();
00057 
00058     // check if all other relevant images have the same type
00059     for (UIntSet::const_iterator it = usedImgs.begin()++; it != usedImgs.end(); ++it) {
00060         vigra::ImageImportInfo info2(pano.getImage(*it).getFilename().c_str());
00061         if ( pixelType != info2.getPixelType() ) {
00062             UTILS_THROW(std::runtime_error, "image " <<
00063                     pano.getImage(*it).getFilename() << " uses " <<
00064                     info2.getPixelType() << " valued pixel, while " <<
00065                     pano.getImage(0).getFilename() << " uses: " << pixelType);
00066             return;
00067         }
00068 
00069         if (info2.numBands() - info2.numExtraBands() != bands - extraBands) {
00070             UTILS_THROW(std::runtime_error, "image " <<
00071                     pano.getImage(*it).getFilename() << " has " <<
00072                     info2.numBands() << " channels, while " <<
00073                     pano.getImage(0).getFilename() << " uses: " << bands);
00074             return;
00075         }
00076     }
00077 //    DEBUG_DEBUG("Output pixel type: " << pixelType);
00078     PanoramaOptions opts = opt;
00079     if (opts.outputMode == PanoramaOptions::OUTPUT_HDR) {
00080         if (opts.outputPixelType.size() == 0) {
00081             opts.outputPixelType = "FLOAT";
00082         }
00083     } else {
00084         if (pano.getImage(0).getResponseType() == HuginBase::BaseSrcPanoImage::RESPONSE_EMOR)
00085         {
00086             // get the emor parameters.
00087             opts.outputEMoRParams = pano.getSrcImage(0).getEMoRParams();
00088         }
00089         else
00090         {
00091             // clear the parameters to indicatate these should not be used
00092             opts.outputEMoRParams.clear();
00093         };
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<vigra::FImage, vigra::BImage>(pano, opts, progress, basename, usedImgs, advOptions);
00107         } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
00108             stitchPanoIntern<vigra::FRGBImage, vigra::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 17 Aug 2017 for Hugintrunk by  doxygen 1.4.7