core/vil/algo/vil_grid_merge.h
Go to the documentation of this file.
00001 #ifndef vil_grid_merge_h_
00002 #define vil_grid_merge_h_
00003 //:
00004 // \file
00005 // \brief Merge two images in a chequer-board pattern.
00006 // \author Tim Cootes
00007 
00008 #include <vil/vil_image_view.h>
00009 #include <vcl_cassert.h>
00010 
00011 //: Merge two images in a chequer-board pattern.
00012 //  image1 and image2 are merged by copying boxes of size (box_ni x box_nj)
00013 //  alternatively from each one.
00014 //  Useful for comparing two images.
00015 //  \relatesalso vil_image_view
00016 template <class T>
00017 inline void vil_grid_merge(const vil_image_view<T>& image1,
00018                            const vil_image_view<T>& image2,
00019                            vil_image_view<T>& dest_image,
00020                            unsigned box_ni, unsigned box_nj)
00021 {
00022   unsigned ni = image1.ni();
00023   unsigned nj = image1.nj();
00024   unsigned np = image1.nplanes();
00025   assert(image2.ni()==ni && image2.nj()==nj && image2.nplanes()==np);
00026 
00027   dest_image.set_size(ni,nj,np);
00028 
00029   for (unsigned p=0;p<np;++p)
00030     for (unsigned j=0;j<nj;++j)
00031       for (unsigned i=0;i<ni;++i)
00032       {
00033         if ( ((i/box_ni)+(j/box_nj))%2 == 0)
00034           dest_image(i,j,p)=image1(i,j,p);
00035         else
00036           dest_image(i,j,p)=image2(i,j,p);
00037       }
00038 }
00039 
00040 #endif // vil_grid_merge_h_