vil_grid_merge.h
Go to the documentation of this file.
1 #ifndef vil_grid_merge_h_
2 #define vil_grid_merge_h_
3 //:
4 // \file
5 // \brief Merge two images in a chequer-board pattern.
6 // \author Tim Cootes
7 
8 #include <vil/vil_image_view.h>
9 #include <cassert>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
14 //: Merge two images in a chequer-board pattern.
15 // image1 and image2 are merged by copying boxes of size (box_ni x box_nj)
16 // alternatively from each one.
17 // Useful for comparing two images.
18 // \relatesalso vil_image_view
19 template <class T>
20 inline void vil_grid_merge(const vil_image_view<T>& image1,
21  const vil_image_view<T>& image2,
22  vil_image_view<T>& dest_image,
23  unsigned box_ni, unsigned box_nj)
24 {
25  unsigned ni = image1.ni();
26  unsigned nj = image1.nj();
27  unsigned np = image1.nplanes();
28  assert(image2.ni()==ni && image2.nj()==nj && image2.nplanes()==np);
29 
30  dest_image.set_size(ni,nj,np);
31 
32  for (unsigned p=0;p<np;++p)
33  for (unsigned j=0;j<nj;++j)
34  for (unsigned i=0;i<ni;++i)
35  {
36  if ( ((i/box_ni)+(j/box_nj))%2 == 0)
37  dest_image(i,j,p)=image1(i,j,p);
38  else
39  dest_image(i,j,p)=image2(i,j,p);
40  }
41 }
42 
43 #endif // vil_grid_merge_h_
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
unsigned ni() const
Width.
unsigned nj() const
Height.
A base class reference-counting view of some image data.
unsigned nplanes() const
Number of planes.
void vil_grid_merge(const vil_image_view< T > &image1, const vil_image_view< T > &image2, vil_image_view< T > &dest_image, unsigned box_ni, unsigned box_nj)
Merge two images in a chequer-board pattern.