PointSampler.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include "PointSampler.h"
00025 
00026 #include <algorithms/basic/CalculateOptimalScale.h>
00027 #include <algorithms/nona/FitPanorama.h>
00028 #include <algorithms/nona/CenterHorizontally.h>
00029 #include <vigra/convolution.hxx>
00030 
00031 namespace HuginBase
00032 {
00033 
00035 LimitIntensity::LimitIntensity()
00036 {
00037     m_minI = -FLT_MAX;
00038     m_maxI = FLT_MAX;
00039 };
00040 
00042 LimitIntensity::LimitIntensity(LimitIntensity::LimitType limit)
00043 {
00044     switch (limit)
00045     {
00046         case LIMIT_UINT8:
00047             m_minI = 1 / 255.0f;
00048             m_maxI = 250 / 255.0f;
00049             break;
00050         case LIMIT_UINT16:
00051             m_minI = 1 / 65535.0f;
00052             m_maxI = 65000 / 65535.0f;
00053             break;
00054         case LIMIT_FLOAT:
00055             m_minI = -FLT_MAX;
00056             m_maxI = FLT_MAX;
00057             break;
00058     };
00059 };
00060 
00061 bool PointSampler::runAlgorithm()
00062 {
00063     // is this correct? how much progress requierd?
00064     sampleAndExtractPoints(getProgressDisplay());
00065     
00066     if (getProgressDisplay()->wasCancelled())
00067     {
00068         cancelAlgorithm();
00069     };
00070 
00071     return wasCancelled();
00072 }
00073 
00074 void PointSampler::sampleAndExtractPoints(AppBase::ProgressDisplay* progress)
00075 {
00076     PanoramaData& pano = *(o_panorama.getNewCopy()); // don't forget to delete!
00077     std::vector<vigra::FRGBImage*>& images = o_images;
00078     int& nPoints = o_numPoints;
00079     std::vector<vigra_ext::PointPairRGB>& points = o_resultPoints;
00080     
00081     std::vector<vigra::FImage *> lapImgs;
00082     std::vector<vigra::Size2D> origsize;
00083     
00084     // convert to interpolating images
00085     typedef vigra_ext::ImageInterpolator<vigra::FRGBImage::const_traverser, vigra::FRGBImage::ConstAccessor, vigra_ext::interp_cubic> InterpolImg;
00086     std::vector<InterpolImg> interpolImages;
00087     
00088     vigra_ext::interp_cubic interp;
00089     // adjust sizes in panorama
00090     for (unsigned i=0; i < pano.getNrOfImages(); i++)
00091     {
00092         SrcPanoImage simg = pano.getSrcImage(i);
00093         origsize.push_back(simg.getSize());
00094         simg.resize(images[i]->size());
00095         pano.setSrcImage(i, simg);
00096         interpolImages.push_back(InterpolImg(srcImageRange(*(images[i])), interp, false));
00097         
00098         vigra::FImage * lap = new vigra::FImage(images[i]->size());
00099         lapImgs.push_back(lap);
00100     }
00101 #pragma omp parallel for
00102     for (int i = 0; i < pano.getNrOfImages(); i++)
00103     {
00104         vigra::laplacianOfGaussian(srcImageRange(*(images[i]), vigra::GreenAccessor<vigra::RGBValue<float> >()), destImage(*(lapImgs[i])), 1);
00105     }
00106     
00107     // extract the overlapping points.
00108 //    PanoramaOptions opts = pano.getOptions();
00109 //    double scale = CalculateOptimalScale::calcOptimalPanoScale(pano.getSrcImage(0),opts);
00110 //    opts.setWidth(utils::roundi(opts.getWidth()*scale), true);    
00111 //    pano.setOptions(opts);
00112     // center panorama and do fit to get minimum of black/unused space around panorama
00113     CenterHorizontally(pano).run();
00114     PanoramaOptions opts = pano.getOptions();
00115     CalculateFitPanorama fitPano(pano);
00116     fitPano.run();
00117     opts.setHFOV(fitPano.getResultHorizontalFOV());
00118     opts.setHeight(hugin_utils::roundi(fitPano.getResultHeight()));
00119     // set roi to maximal size, so that the whole panorama is used for sampling
00120     // a more reasonable solution would be to use the maximal
00121     // used area, but this is currently not support to
00122     // calculate optimal roi
00123     opts.setROI(vigra::Rect2D(opts.getSize()));
00124     pano.setOptions(opts);
00125     SetWidthOptimal(pano).run();
00126     
00127     // if random points.
00128     // extract random points.
00129     // need to get the maximum gray value here..
00130     
00131     std::vector<std::multimap<double, vigra_ext::PointPairRGB> > radiusHist(10);
00132     
00133     unsigned nGoodPoints = 0;
00134     unsigned nBadPoints = 0;
00135     
00136     
00137     // call the samplePoints method of this class
00138     progress->setMessage("sampling points");
00139     samplePoints(interpolImages,
00140                  lapImgs,
00141                  pano,
00142                  m_limits,
00143                  radiusHist,
00144                  nGoodPoints,
00145                  nBadPoints,
00146                  progress);
00147         
00148     // select points with low laplacian of gaussian values.
00149     progress->setMessage("extracting good points");
00150     sampleRadiusUniform(radiusHist, nPoints, points, progress);
00151     
00152     // scale point coordinates to fit into original panorama.
00153     for (size_t i=0; i < points.size(); i++) {
00154         double scaleF1 = origsize[points[i].imgNr1].x / (float) images[points[i].imgNr1]->size().x;
00155         double scaleF2 = origsize[points[i].imgNr2].x / (float) images[points[i].imgNr2]->size().x;
00156         points[i].p1.x = points[i].p1.x * scaleF1;
00157         points[i].p1.y = points[i].p1.y * scaleF1;
00158         points[i].p2.x = points[i].p2.x * scaleF2;
00159         points[i].p2.y = points[i].p2.y * scaleF2;
00160     }
00161 
00162     for (size_t i=0; i < images.size(); i++) {
00163         delete images[i];
00164         delete lapImgs[i];
00165     }
00166     
00167     delete &pano; // deleting the NewCopy
00168 }
00169 
00170 }; // namespace
00171 

Generated on 7 Dec 2016 for Hugintrunk by  doxygen 1.4.7