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 template<class T>
00017 inline vil_image_view<T> vil_flatten_planes(const vil_image_view<T> &im)
00018 {
00019   if (im.nplanes() == 1) return im;
00020   if (im.jstep() * im.nj() == im.planestep())
00021   {
00022     return vil_image_view<T>(im.memory_chunk(),
00023                              im.top_left_ptr(),
00024                              im.ni(), im.nj() * im.nplanes(), 1,
00025                              im.istep(),im.jstep(),im.ni() * im.nj() * im.nplanes());
00026   }
00027 
00028   vil_image_view<T> ret(im.ni(), im.nj() * im.nplanes(), 1);
00029   for (unsigned p=0, n=im.nplanes(); p<n; ++p)
00030   {
00031     vil_image_view<T> tile = vil_crop(ret, 0, im.ni(), im.nj()*p, im.nj());
00032     vil_copy_reformat(vil_plane(im, p), tile);
00033   }
00034 
00035   return ret;
00036 }
00037 
00038 #endif // vil_flatten_h_

Generated on Tue Oct 7 05:07:42 2008 for core/vil by  doxygen 1.5.1