vil_tile_images.h
Go to the documentation of this file.
1 // This is core/vil/algo/vil_tile_images.h
2 #ifndef vil_tile_images_h_
3 #define vil_tile_images_h_
4 //:
5 // \file
6 // \brief Create a big image by tiling images in patches
7 // \author Tim Cootes
8 
9 #include <vector>
10 #include <cmath>
11 #include <vil/vil_image_view.h>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 #include <cassert>
16 
17 //: Create a big image by tiling images in patches (must be of same size).
18 // Creates a large image by putting smaller images into an approximately
19 // square grid.
20 // If there are n small images, the grid will have sqrt(n) columns.
21 // \sa contrib/mul/tools/tile_images_2d
22 // \relatesalso vil_image_view
23 template<class T>
24 inline void vil_tile_images(vil_image_view<T>& big_image,
25  const std::vector<vil_image_view<T> >& patches)
26 {
27  unsigned n = patches.size();
28  unsigned nj = unsigned(std::sqrt(float(n)));
29  unsigned ni = 1+(n-1)/nj;
30 
31  unsigned pi = patches[0].ni();
32  unsigned pj = patches[0].nj();
33  unsigned np = patches[0].nplanes();
34 
35  big_image.set_size(ni*pi,nj*pj);
36  big_image.fill(vxl_byte(0));
37  for (unsigned k=0;k<n;++k)
38  {
39  assert(patches[k].ni()==pi && patches[k].nj()== pj &&
40  patches[k].nplanes()== np);
41 
42  unsigned i = k%ni;
43  unsigned j = k/ni;
44  for (unsigned y=0;y<pj;++y)
45  for (unsigned x=0;x<pi;++x)
46  for (unsigned p=0;p<np;++p)
47  big_image(i*pi+x,j*pj+y,p) = patches[k](x,y,p);
48  }
49 }
50 
51 #endif // vil_tile_images_h_
void vil_tile_images(vil_image_view< T > &big_image, const std::vector< vil_image_view< T > > &patches)
Create a big image by tiling images in patches (must be of same size).
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void fill(T value)
Fill view with given value.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
A base class reference-counting view of some image data.