Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageDistribution.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __IMAGE_DISTRIBUTION_HH__
26 #define __IMAGE_DISTRIBUTION_HH__
27 
28 // std
29 #include <iostream>
30 #include <math.h>
31 #include <vector>
32 
33 // BIAS
34 #include <Base/Math/Vector2.hh>
35 #include <Base/Image/Image.hh>
36 #include <Base/Image/ImageIO.hh>
37 
38 namespace BIAS
39 {
40  /**
41  * @brief Maps a set of input images to a given output image so that the space
42  * in the output image area is optimally used.
43  *
44  * The images are aligned in a grid so that minimal space is wasted. The
45  * intended use of this class is texture fusion.
46  *
47  * @author rwulff
48  * @date 03/2011
49  */
50  class BIASImageUtilsBase_EXPORT ImageDistribution
51  {
52 
53  public:
54 
55  /**
56  * @brief Maps the given images to the output image, which is of a fixed
57  * size.
58  *
59  * Scaling is performed by nearest neighbour backward mapping.
60  *
61  * @warning Assumes that all input images have the same size and channel
62  * count. This is not checked!!!
63  *
64  * @param[in] inputImages
65  * the input images. must all have the same size and channel
66  * count (not checked!)
67  * @param[out] outputImage
68  * the destination image. must have (width, height > 0). channel
69  * count must be same as input images.
70  * @param[out] imagePositionsPixel
71  * upper left corner of each input image in the output image
72  */
73  static
74  void MapImagesToFixedSize(std::vector<Image<unsigned char> > &inputImages,
75  Image<unsigned char> &outputImage,
76  std::vector<Vector2<unsigned int> > &imagePositionsPixel);
77  static
78  void MapImagesToFixedSize(const std::vector<Image<unsigned char>*> &inputImages,
79  Image<unsigned char> &outputImage,
80  std::vector<Vector2<unsigned int> > &imagePositionsPixel);
81  /**
82  * @brief Maps the given images to a square without scaling the images.
83  *
84  * The images are distributed to utilize a square area optimally. The output
85  * image will be sized so that it can hold all images.
86  *
87  * @warning Assumes that all input images have the same size and channel
88  * count. This is not checked!!!
89  *
90  * @param[in] inputImages
91  * the input images. must all have the same size and channel
92  * count (not checked!)
93  * @param[out] outputImage
94  * the destination image. size is ignored. channel count must be
95  * same as input images
96  * @param[out] imagePositionsPixel
97  * upper left corner of each input image in the output image
98  */
99  static
100  void MapImagesToSquare(std::vector<Image<unsigned char> > &inputImages,
101  Image<unsigned char> &outputImage,
102  std::vector<Vector2<unsigned int> > &imagePositionsPixel);
103  static
104  void MapImagesToSquare(const std::vector<Image<unsigned char>*> &inputImage,
105  Image<unsigned char> &outputImage,
106  std::vector<Vector2<unsigned int> > &imagePositionsPixel);
107 
108  private:
109 
110  /**
111  * @brief Computes the number of rows and columns of the grid and the scale
112  * factor.
113  *
114  * @todo early termination possible when scales lower again
115  * @todo iteration in the other direction will find the maximum earlier if
116  * early termination is used
117  *
118  * @param[in] numImages
119  * number of input images
120  * @param[in] widthIn
121  * width of each input image
122  * @param[in] heightIn
123  * height of each input image
124  * @param[in] heightOut
125  * height of the output image
126  * @param[in] heightOut
127  * height of the output image
128  * @param[out] numCols
129  * the number of columns in the grid
130  * @param[out] numRows
131  * the number of rows in the grid
132  * @param[out] scale
133  * the scale factor
134  */
135  static
136  void ComputeGridAndScale(unsigned int numImages,
137  unsigned int widthIn,
138  unsigned int heightIn,
139  unsigned int widthOut,
140  unsigned int heightOut,
141  unsigned int &numCols,
142  unsigned int &numRows,
143  float &scale);
144 
145  /**
146  * @brief For each input image computes the upper left corner in the output
147  * image.
148  *
149  * @param[in] numImages
150  * number of input images
151  * @param[in] widthIn
152  * width of each input image
153  * @param[in] heightIn
154  * height of each input image
155  * @param[in] numCols
156  * the number of columns in the grid
157  * @param[in] numRows
158  * the number of rows in the grid
159  * @param[in] scale
160  * the scale factor
161  * @param[out] imagePositionsGrid
162  * abstract position of each input image in the grid (col, row)
163  * @param[out] imagePositionsPixel
164  * upper left corner position of each input image in pixels
165  * @param[out] imageIndices
166  * inverse mapping of imagePositionsGrid: stores corresponding
167  * image index for each grid position. -1 == no image at this
168  * position. first index is row, second is column
169  */
170  static
171  void ComputeImagePositions(unsigned int numImages,
172  unsigned int widthIn,
173  unsigned int heightIn,
174  unsigned int numRows,
175  unsigned int numCols,
176  float scale,
177  std::vector<Vector2<unsigned int> > &imagePositionsGrid,
178  std::vector<Vector2<unsigned int> > &imagePositionsPixel,
179  std::vector<std::vector<int> > &imageIndices);
180 
181  }; // end of class
182 } // end of namespace
183 
184 #endif // __IMAGE_DISTRIBUTION_HH__
Maps a set of input images to a given output image so that the space in the output image area is opti...