RandomPointSampler.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _Hgn1_RANDOM_POINT_SAMPLER_H
00025 #define _Hgn1_RANDOM_POINT_SAMPLER_H
00026 
00027 #include <algorithms/point_sampler/PointSampler.h>
00028 
00029 #include <vigra/functorexpression.hxx>
00030 #include <vigra_ext/impexalpha.hxx>
00031 #include "PT/Panorama.h"
00032 
00033 namespace PT
00034 {
00035     
00036     
00037     inline void extractPoints(Panorama pano, std::vector<vigra::FRGBImage*> images, int nPoints,
00038                               bool randomPoints, AppBase::ProgressReporter & progress,
00039                               std::vector<vigra_ext::PointPairRGB> & points  )
00040     {
00041         HuginBase::PointSampler::extractPoints(pano, images, nPoints, randomPoints, progress, points);
00042     }
00043     
00044     
00045     template<class ImageType>
00046         std::vector<ImageType *> loadImagesPyr(std::vector<std::string> files, int pyrLevel, int verbose=0)
00047     {
00048             typedef typename ImageType::value_type PixelType;
00049             std::vector<ImageType *> srcImgs;
00050             for (size_t i=0; i < files.size(); i++) {
00051                 ImageType * tImg = new ImageType();
00052                 ImageType * tImg2 = new ImageType();
00053                 vigra::ImageImportInfo info(files[i].c_str());
00054                 tImg->resize(info.size());
00055                 if (verbose)
00056                     std::cout << "loading: " << files[i] << std::endl;
00057                 
00058                 if (info.numExtraBands() == 1) {
00059                     // dummy mask
00060                     vigra::BImage mask(info.size());
00061                     vigra::importImageAlpha(info, vigra::destImage(*tImg), vigra::destImage(mask));
00062                 } else {
00063                     vigra::importImage(info, vigra::destImage(*tImg));
00064                 }
00065                 float div = 1;
00066                 if (strcmp(info.getPixelType(), "UINT8") == 0) {
00067                     div = 255;
00068                 } else if (strcmp(info.getPixelType(), "UINT16") == 0) {
00069                     div = (1<<16)-1;
00070                 }
00071                 
00072                 if (pyrLevel) {
00073                     ImageType * swap;
00074                     // create downscaled image
00075                     if (verbose > 0) {
00076                         std::cout << "downscaling: ";
00077                     }
00078                     for (int l=pyrLevel; l > 0; l--) {
00079                         if (verbose > 0) {
00080                             std::cout << tImg->size().x << "x" << tImg->size().y << "  " << std::flush;
00081                         }
00082                         vigra_ext::reduceToNextLevel(*tImg, *tImg2);
00083                         swap = tImg;
00084                         tImg = tImg2;
00085                         tImg2 = swap;
00086                     }
00087                     if (verbose > 0)
00088                         std::cout << std::endl;
00089                 }
00090                 if (div > 1) {
00091                     div = 1/div;
00092                     transformImage(vigra::srcImageRange(*tImg), vigra::destImage(*tImg),
00093                                    vigra::functor::Arg1()*vigra::functor::Param(div));
00094                 }
00095                 srcImgs.push_back(tImg);
00096                 delete tImg2;
00097             }
00098             return srcImgs;
00099     }
00100     
00101     
00102     // needs 2.0 progress steps
00103     inline void loadImgsAndExtractPoints(Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressReporter& progress, std::vector<vigra_ext::PointPairRGB> & points  )
00104     {
00105         // extract file names
00106         std::vector<std::string> files;
00107         for (size_t i=0; i < pano.getNrOfImages(); i++)
00108             files.push_back(pano.getImage(i).getFilename());
00109         
00110         std::vector<vigra::FRGBImage*> images;
00111         
00112         // try to load the images.
00113         images = loadImagesPyr<vigra::FRGBImage>(files, pyrLevel, 1);
00114         
00115         HuginBase::PointSampler::extractPoints(pano, images, nPoints, randomPoints, progress, points);
00116     }
00117 };
00118 
00119 #endif

Generated on Tue Sep 2 01:25:40 2014 for Hugintrunk by  doxygen 1.3.9.1