LayerStacks.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00008  /*  This is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This software is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public
00019  *  License along with this software. If not, see
00020  *  <http://www.gnu.org/licenses/>.
00021  *
00022  */
00023 
00024 #include "LayerStacks.h"
00025 
00026 #include <panodata/PanoramaData.h>
00027 #include <panodata/StandardImageVariableGroups.h>
00028 #include <algorithms/basic/CalculateOverlap.h>
00029 #include <algorithms/nona/ComputeImageROI.h>
00030 
00031 namespace HuginBase
00032 {
00033 
00034 std::vector<UIntSet> getHDRStacks(const PanoramaData & pano, UIntSet allImgs, PanoramaOptions opts)
00035 {
00036     std::vector<UIntSet> result;
00037 
00038     // if no images are available, return empty result vector
00039     if ( allImgs.empty() )
00040     {
00041         return result;
00042     }
00043 
00044     // special case: for a negtive overlap use the assigned stacks and skip
00045     // overlap calculation
00046     if (opts.outputStacksMinOverlap < 0)
00047     {
00048         HuginBase::ConstStandardImageVariableGroups variable_groups(pano);
00049         return variable_groups.getStacks().getPartsSet();
00050     };
00051 
00052     UIntSet stack;
00053 
00054     CalculateImageOverlap overlap(&pano);
00055     overlap.calculate(10);  // we are testing 10*10=100 points
00056     do
00057     {
00058         const unsigned srcImg = *(allImgs.begin());
00059         stack.insert(srcImg);
00060         allImgs.erase(srcImg);
00061 
00062         // find all images that have a suitable overlap.
00063         for (UIntSet::const_iterator it = allImgs.begin(); it != allImgs.end(); ++it)
00064         {
00065             const unsigned srcImg2 = *it;
00066             if (overlap.getOverlap(srcImg, srcImg2) > opts.outputStacksMinOverlap)
00067             {
00068                 stack.insert(srcImg2);
00069             };
00070         };
00071         for (UIntSet::const_iterator it = stack.begin(); it != stack.end(); ++it)
00072         {
00073             allImgs.erase(*it);
00074         };
00075         result.push_back(stack);
00076         stack.clear();
00077     } while (!allImgs.empty());
00078 
00079     return result;
00080 }
00081 
00082 std::vector<UIntSet> getExposureLayers(const PanoramaData & pano, UIntSet allImgs, PanoramaOptions opts)
00083 {
00084     return getExposureLayers(pano, allImgs, opts.outputLayersExposureDiff);
00085 };
00086 
00087 std::vector<UIntSet> getExposureLayers(const PanoramaData & pano, UIntSet allImgs, const double maxEVDiff)
00088 {
00089     std::vector<UIntSet> result;
00090 
00091     // if no images are available, return empty result vector
00092     if ( allImgs.empty() )
00093     {
00094         return result;
00095     }
00096 
00097     UIntSet layer;
00098 
00099     do
00100     {
00101         const unsigned srcImg = *(allImgs.begin());
00102         layer.insert(srcImg);
00103         allImgs.erase(srcImg);
00104 
00105         // find all images that have a similar exposure values.
00106         const double firstExposureValue = pano.getImage(srcImg).getExposureValue();
00107         for (UIntSet::const_iterator it = allImgs.begin(); it !=  allImgs.end(); ++it)
00108         {
00109             const unsigned srcImg2 = *it;
00110             if ( fabs(firstExposureValue - pano.getImage(srcImg2).getExposureValue()) < maxEVDiff )
00111             {
00112                 layer.insert(srcImg2);
00113             }
00114         }
00115         for (UIntSet::const_iterator it = layer.begin(); it != layer.end(); ++it)
00116         {
00117             allImgs.erase(*it);
00118         };
00119         result.push_back(layer);
00120         layer.clear();
00121     } while (!allImgs.empty());
00122 
00123     return result;
00124 }
00125 
00126 UIntSet getImagesinROI (const PanoramaData& pano, const UIntSet activeImages)
00127 {
00128     return getImagesinROI(pano, activeImages, pano.getOptions().getROI());
00129 }
00130 
00131 UIntSet getImagesinROI(const PanoramaData& pano, const UIntSet activeImages, vigra::Rect2D panoROI)
00132 {
00133     UIntSet images;
00134     PanoramaOptions opts = pano.getOptions();
00135     opts.setROI(panoROI);
00136     for (UIntSet::const_iterator it = activeImages.begin(); it != activeImages.end(); ++it)
00137     {
00138         vigra::Rect2D roi = estimateOutputROI(pano, opts, *it);
00139         if (!(roi.isEmpty()))
00140         {
00141             images.insert(*it);
00142         }
00143     }
00144     return images;
00145 }
00146 
00147 struct SortVectorByExposure
00148 {
00149     explicit SortVectorByExposure(const HuginBase::Panorama* pano) : m_pano(pano) {};
00150     bool operator()(const size_t& img1, const size_t& img2)
00151     {
00152         return m_pano->getImage(img1).getExposureValue() < m_pano->getImage(img2).getExposureValue();
00153     }
00154 private:
00155     const HuginBase::Panorama* m_pano;
00156 };
00157 
00158 std::vector<HuginBase::UIntVector> getSortedStacks(const HuginBase::Panorama* pano)
00159 {
00160     std::vector<HuginBase::UIntVector> stacks;
00161     if (pano->getNrOfImages() == 0)
00162     {
00163         return stacks;
00164     };
00165     HuginBase::ConstStandardImageVariableGroups variable_groups(*pano);
00166     HuginBase::UIntSetVector imageGroups = variable_groups.getStacks().getPartsSet();
00167     //get image with median exposure for search with cp generator
00168     for (size_t imgGroup = 0; imgGroup < imageGroups.size(); ++imgGroup)
00169     {
00170         HuginBase::UIntVector stackImages(imageGroups[imgGroup].begin(), imageGroups[imgGroup].end());
00171         std::sort(stackImages.begin(), stackImages.end(), SortVectorByExposure(pano));
00172         stacks.push_back(stackImages);
00173     };
00174     return stacks;
00175 };
00176 
00177 }

Generated on 10 Feb 2016 for Hugintrunk by  doxygen 1.4.7