Basic Image AlgorithmS Library 2.8.0

ImageDistribution.hh

00001 /*
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #ifndef __IMAGE_DISTRIBUTION_HH__
00026 #define __IMAGE_DISTRIBUTION_HH__
00027 
00028 // std
00029 #include <iostream>
00030 #include <math.h>
00031 #include <vector>
00032 
00033 // BIAS
00034 #include <Base/Math/Vector2.hh>
00035 #include <Base/Image/Image.hh>
00036 #include <Base/Image/ImageIO.hh>
00037 
00038 namespace BIAS
00039 {
00040   /**
00041    * @brief Maps a set of input images to a given output image so that the space
00042    *        in the output image area is optimally used.
00043    *
00044    * The images are aligned in a grid so that minimal space is wasted. The
00045    * intended use of this class is texture fusion.
00046    *
00047    * @author rwulff
00048    * @date   03/2011
00049    */
00050   class BIASImageUtilsBase_EXPORT ImageDistribution
00051   {
00052 
00053   public:
00054 
00055     /**
00056      * @brief Maps the given images to the output image, which is of a fixed
00057      *        size.
00058      *
00059      * Scaling is performed by nearest neighbour backward mapping.
00060      *
00061      * @warning Assumes that all input images have the same size and channel
00062      *          count. This is not checked!!!
00063      *
00064      * @param[in]  inputImages
00065      *             the input images. must all have the same size and channel
00066      *             count (not checked!)
00067      * @param[out] outputImage
00068      *             the destination image. must have (width, height > 0). channel
00069      *             count must be same as input images.
00070      * @param[out] imagePositionsPixel
00071      *             upper left corner of each input image in the output image
00072      */
00073     static
00074     void MapImagesToFixedSize(std::vector<Image<unsigned char> > &inputImages,
00075                               Image<unsigned char> &outputImage,
00076                               std::vector<Vector2<unsigned int> > &imagePositionsPixel);
00077     static
00078     void MapImagesToFixedSize(const std::vector<Image<unsigned char>*> &inputImages,
00079                               Image<unsigned char> &outputImage,
00080                               std::vector<Vector2<unsigned int> > &imagePositionsPixel);
00081     /**
00082      * @brief Maps the given images to a square without scaling the images.
00083      *
00084      * The images are distributed to utilize a square area optimally. The output
00085      * image will be sized so that it can hold all images.
00086      *
00087      * @warning Assumes that all input images have the same size and channel
00088      *          count. This is not checked!!!
00089      *
00090      * @param[in]  inputImages
00091      *             the input images. must all have the same size and channel
00092      *             count (not checked!)
00093      * @param[out] outputImage
00094      *             the destination image. size is ignored. channel count must be
00095      *             same as input images
00096      * @param[out] imagePositionsPixel
00097      *             upper left corner of each input image in the output image
00098      */
00099     static
00100     void MapImagesToSquare(std::vector<Image<unsigned char> > &inputImages,
00101                            Image<unsigned char> &outputImage,
00102                            std::vector<Vector2<unsigned int> > &imagePositionsPixel);
00103     static
00104     void MapImagesToSquare(const std::vector<Image<unsigned char>*> &inputImage,
00105                            Image<unsigned char> &outputImage,
00106                            std::vector<Vector2<unsigned int> > &imagePositionsPixel);
00107     
00108   private:
00109 
00110     /**
00111      * @brief Computes the number of rows and columns of the grid and the scale
00112      *        factor.
00113      *
00114      * @todo early termination possible when scales lower again
00115      * @todo iteration in the other direction will find the maximum earlier if
00116      *       early termination is used
00117      *
00118      * @param[in]  numImages
00119      *             number of input images
00120      * @param[in]  widthIn
00121      *             width of each input image
00122      * @param[in]  heightIn
00123      *             height of each input image
00124      * @param[in]  heightOut
00125      *             height of the output image
00126      * @param[in]  heightOut
00127      *             height of the output image
00128      * @param[out] numCols
00129      *             the number of columns in the grid
00130      * @param[out] numRows
00131      *             the number of rows in the grid
00132      * @param[out] scale
00133      *             the scale factor
00134      */
00135     static
00136     void ComputeGridAndScale(unsigned int numImages,
00137                              unsigned int widthIn,
00138                              unsigned int heightIn,
00139                              unsigned int widthOut,
00140                              unsigned int heightOut,
00141                              unsigned int &numCols,
00142                              unsigned int &numRows,
00143                              float &scale);
00144 
00145     /**
00146      * @brief For each input image computes the upper left corner in the output
00147      *        image.
00148      *
00149      * @param[in]  numImages
00150      *             number of input images
00151      * @param[in]  widthIn
00152      *             width of each input image
00153      * @param[in]  heightIn
00154      *             height of each input image
00155      * @param[in]  numCols
00156      *             the number of columns in the grid
00157      * @param[in]  numRows
00158      *             the number of rows in the grid
00159      * @param[in]  scale
00160      *             the scale factor
00161      * @param[out] imagePositionsGrid
00162      *             abstract position of each input image in the grid (col, row)
00163      * @param[out] imagePositionsPixel
00164      *             upper left corner position of each input image in pixels
00165      * @param[out] imageIndices
00166      *             inverse mapping of imagePositionsGrid: stores corresponding
00167      *             image index for each grid position. -1 == no image at this
00168      *             position. first index is row, second is column
00169      */
00170     static
00171     void ComputeImagePositions(unsigned int numImages,
00172                                unsigned int widthIn,
00173                                unsigned int heightIn,
00174                                unsigned int numRows,
00175                                unsigned int numCols,
00176                                float scale,
00177                                std::vector<Vector2<unsigned int> > &imagePositionsGrid,
00178                                std::vector<Vector2<unsigned int> > &imagePositionsPixel,
00179                                std::vector<std::vector<int> > &imageIndices);
00180 
00181   }; // end of class
00182 } // end of namespace
00183 
00184 #endif // __IMAGE_DISTRIBUTION_HH__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends