vil_warp.h
Go to the documentation of this file.
1 // This is core/vil/vil_warp.h
2 #ifndef vil_warp_h_
3 #define vil_warp_h_
4 //:
5 // \file
6 // \brief Warp an image.
7 // \author awf@robots.ox.ac.uk
8 // \date 04 Dec 00
9 // \verbatim
10 // Modifications
11 // 031201 IMS Convert to vil2. Used templates to simplify interface and code.
12 // \endverbatim
13 
14 #include <vil/vil_fwd.h>
15 #include <cassert>
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 
20 //: Warp an image under a 2D map.
21 // The size of the output map and the mapper defines the region of
22 // the input image to be scanned.
23 // \param mapper, is the inverse of the mapping from the input image's
24 // co-ordinate frame to the output image's frame.
25 // i.e. out() = in(mapper(x,y)). It should be a functor with a signature
26 // \code
27 // void mapper(double x_in, double y_in, double* x_out, double* y_out);
28 // \endcode
29 // \param interp, is an interpolator, with a signature similar to
30 // \code
31 // S vil_bilin_interp_safe(const vil_image_view<T>&, double, double, unsigned)
32 // \endcode
33 //
34 // Note that if you want to store a warp with an image to create a registered image,
35 // the vimt library (in contrib/mul/vimt) provides efficient registered images
36 // with transforms up to projective.
37 //
38 // \relatesalso vil_image_view
39 template <class sType, class dType, class MapFunctor, class InterpFunctor>
42  MapFunctor mapper,
43  InterpFunctor interp)
44 {
45  unsigned const out_w = out.ni();
46  unsigned const out_h = out.nj();
47 
48  assert(out.nplanes() == in.nplanes());
49 
50  for (unsigned p = 0; p < out.nplanes(); ++p)
51  {
52  for (unsigned oy = 0; oy < out_h; ++oy)
53  {
54  for (unsigned ox = 0; ox < out_w; ++ox)
55  {
56  // *** Find (ix, iy) from (ox,oy)
57  double ix, iy;
58  mapper(double(ox), double(oy), ix, iy);
59  out(ox, oy, p) = dType(interp(in, ix, iy, p));
60  }
61  }
62  }
63 }
64 
65 #endif // vil_warp_h_
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void vil_warp(const vil_image_view< sType > &in, vil_image_view< dType > &out, MapFunctor mapper, InterpFunctor interp)
Warp an image under a 2D map.
Definition: vil_warp.h:40
unsigned ni() const
Width.
unsigned nj() const
Height.
unsigned nplanes() const
Number of planes.