core/vil/vil_flatten.h
Go to the documentation of this file.
00001 // This is core/vil/vil_flatten.h
00002 #ifndef vil_flatten_h_
00003 #define vil_flatten_h_
00004 //:
00005 // \file
00006 // \author Ian Scott.
00007 
00008 #include <vil/vil_image_view.h>
00009 #include <vil/vil_crop.h>
00010 #include <vil/vil_plane.h>
00011 
00012 
00013 //: Rearrange multiple planes into a multiple tiles of a single-plane image.
00014 // A ni x nj x nplanes images will be arranged into an ni x (nj*nplanes) x 1 image.
00015 // A view transformation will be used if possible.
00016 // \relatesalso vil_image_view
00017 template<class T>
00018 inline vil_image_view<T> vil_flatten_planes(const vil_image_view<T> &im)
00019 {
00020   if (im.nplanes() == 1) return im;
00021   if (im.jstep() * im.nj() == im.planestep())
00022   {
00023     return vil_image_view<T>(im.memory_chunk(),
00024                              im.top_left_ptr(),
00025                              im.ni(), im.nj() * im.nplanes(), 1,
00026                              im.istep(),im.jstep(),im.ni() * im.nj() * im.nplanes());
00027   }
00028 
00029   vil_image_view<T> ret(im.ni(), im.nj() * im.nplanes(), 1);
00030   for (unsigned p=0, n=im.nplanes(); p<n; ++p)
00031   {
00032     vil_image_view<T> tile = vil_crop(ret, 0, im.ni(), im.nj()*p, im.nj());
00033     vil_copy_reformat(vil_plane(im, p), tile);
00034   }
00035 
00036   return ret;
00037 }
00038 
00039 #endif // vil_flatten_h_