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         // get the emor parameters.
00085         opts.outputEMoRParams = pano.getSrcImage(0).getEMoRParams();
00086         if (opts.outputPixelType.size() == 0) {
00087             opts.outputPixelType = pixelType;
00088         } else {
00089             // if output format is specified, use output format as stitching format
00090             // TODO: this will fail when going down in precision: UINT16 -> UINT8
00091             pixelType = opts.outputPixelType;
00092         }
00093     }
00094 
00095 #if 1
00096     if (opts.outputMode == PanoramaOptions::OUTPUT_HDR) {
00097         if (bands == 1 || (bands == 2 && extraBands == 1)) {
00098             stitchPanoIntern<vigra::FImage, vigra::BImage>(pano, opts, progress, basename, usedImgs, advOptions);
00099         } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
00100             stitchPanoIntern<vigra::FRGBImage, vigra::BImage>(pano, opts, progress, basename, usedImgs, advOptions);
00101         } else {
00102             DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
00103             throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
00104         }
00105     } else {
00106         // stitch the pano with a suitable image type
00107         if (bands == 1 || (bands == 2 && extraBands == 1)) {
00108             if (pixelType ==  "UINT8"||
00109                 pixelType == "INT16" ||
00110                 pixelType == "UINT16" )
00111             {
00112                 stitchPanoGray_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00113             } else {
00114                 stitchPanoGray_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00115             }
00116         } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
00117             if (pixelType == "UINT8" ||
00118                 pixelType == "INT16" ||
00119                 pixelType == "UINT16" )
00120             {
00121                 stitchPanoRGB_8_16(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00122             } else {
00123                 stitchPanoRGB_32_float(pano, opts, progress, basename, usedImgs, pixelType.c_str(), advOptions);
00124             }
00125         }
00126     }
00127 #else
00128     // always stitch with float images.
00129     if (bands == 1 || (bands == 2 && extraBands == 1)) {
00130         stitchPanoIntern<FImage,BImage>(pano, opts, progress, basename, usedImgs);
00131     } else if (bands == 3 || (bands == 4 && extraBands == 1)) {
00132         stitchPanoIntern<FRGBImage,BImage>(pano, opts, progress, basename, usedImgs);
00133     } else {
00134         DEBUG_ERROR("unsupported depth, only images with 1 and 3 channel images are supported");
00135         throw std::runtime_error("unsupported depth, only images with 1 and 3 channel images are supported");
00136         return;
00137     }
00138 #endif
00139 }
00140 
00141 
00142 } // namespace
00143 } // namespace
00144 

Generated on 27 May 2016 for Hugintrunk by  doxygen 1.4.7