vil_flatten.h
Go to the documentation of this file.
1 // This is core/vil/vil_flatten.h
2 #ifndef vil_flatten_h_
3 #define vil_flatten_h_
4 //:
5 // \file
6 // \author Ian Scott.
7 
8 #include <vil/vil_image_view.h>
9 #include <vil/vil_crop.h>
10 #include <vil/vil_plane.h>
11 
12 
13 //: Rearrange multiple planes into a multiple tiles of a single-plane image.
14 // A ni x nj x nplanes images will be arranged into an ni x (nj*nplanes) x 1 image.
15 // A view transformation will be used if possible.
16 // \relatesalso vil_image_view
17 template<class T>
19 {
20  if (im.nplanes() == 1) return im;
21  if (im.jstep() * im.nj() == im.planestep())
22  {
23  return vil_image_view<T>(im.memory_chunk(),
24  im.top_left_ptr(),
25  im.ni(), im.nj() * im.nplanes(), 1,
26  im.istep(),im.jstep(),im.ni() * im.nj() * im.nplanes());
27  }
28 
29  vil_image_view<T> ret(im.ni(), im.nj() * im.nplanes(), 1);
30  for (unsigned p=0, n=im.nplanes(); p<n; ++p)
31  {
32  vil_image_view<T> tile = vil_crop(ret, 0, im.ni(), im.nj()*p, im.nj());
33  vil_copy_reformat(vil_plane(im, p), tile);
34  }
35 
36  return ret;
37 }
38 
39 #endif // vil_flatten_h_
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
vil_image_view< T > vil_flatten_planes(const vil_image_view< T > &im)
Rearrange multiple planes into a multiple tiles of a single-plane image.
Definition: vil_flatten.h:18
void vil_copy_reformat(const vil_image_view< T > &src, vil_image_view< T > &dest)
Copy src to dest, without changing dest's view parameters.
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
vil_image_view< T > vil_plane(const vil_image_view< T > &im, unsigned p)
Return a view of im's plane p.
Definition: vil_plane.h:20
unsigned nplanes() const
Number of planes.
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
vil_image_view< T > vil_crop(const vil_image_view< T > &im, unsigned i0, unsigned n_i, unsigned j0, unsigned n_j)
Create a view which is a cropped version of src.
Definition: vil_crop.h:21
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.