00001
00002 #ifndef vil_flatten_h_
00003 #define vil_flatten_h_
00004
00005
00006
00007
00008 #include <vil/vil_image_view.h>
00009 #include <vil/vil_crop.h>
00010 #include <vil/vil_plane.h>
00011
00012
00013
00014
00015
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_