2 #ifndef vpgl_lens_warp_mapper_h_ 3 #define vpgl_lens_warp_mapper_h_ 11 #include <vil/vil_image_view.h> 18 # include <vcl_msvc_warnings.h> 24 template <
class DataT,
class BoxT>
28 BoxT step_size = BoxT(1))
31 for (BoxT x=box.
min_x(); x<=box.
max_x(); x+=step_size){
37 for (BoxT y=box.
min_y(); y<=box.
max_y(); y+=step_size){
49 template <
class DataT,
class BoxT>
53 BoxT step_size = BoxT(1))
56 for (BoxT x=box.
min_x(); x<=box.
max_x(); x+=step_size){
62 for (BoxT y=box.
min_y(); y<=box.
max_y(); y+=step_size){
76 template <
class sType,
class dType,
class T,
class InterpFunctor>
86 vil_image_view<dType> out(
bounds.width(),
bounds.height(), in.nplanes());
95 template <
class sType,
class dType,
class T,
class InterpFunctor>
97 vil_image_view<dType>& out,
101 unsigned const out_w = out.ni();
102 unsigned const out_h = out.nj();
104 assert(out.nplanes() == in.nplanes());
107 for (
unsigned oy = 0; oy < out_h; ++oy)
110 for (
unsigned ox = 0; ox < out_w; ++ox)
115 if (oy == 0) init = unwarp_pt;
116 ix = unwarp_pt.
x()/unwarp_pt.
w();
117 iy = unwarp_pt.
y()/unwarp_pt.
w();
118 for (
unsigned p = 0; p < out.nplanes(); ++p)
120 out(ox, oy, p) = dType(interp(in, ix, iy, p));
131 template <
class sType,
class dType,
class T,
class InterpFunctor>
132 vil_image_view<dType>
136 InterpFunctor interp)
141 vil_image_view<dType> out(
bounds.width(),
bounds.height(), in.nplanes());
148 template <
class sType,
class dType,
class T,
class InterpFunctor>
150 vil_image_view<dType>& out,
152 InterpFunctor interp)
154 unsigned const out_w = out.ni();
155 unsigned const out_h = out.nj();
157 assert(out.nplanes() == in.nplanes());
159 for (
unsigned oy = 0; oy < out_h; ++oy)
161 for (
unsigned ox = 0; ox < out_w; ++ox)
164 for (
unsigned p = 0; p < out.nplanes(); ++p)
166 out(ox, oy, p) = dType(interp(in, pt.
x(), pt.
y(), p));
172 #endif // vpgl_lens_warp_mapper_h_
virtual vgl_homg_point_2d< T > undistort(const vgl_homg_point_2d< T > &point, const vgl_homg_point_2d< T > *init=nullptr) const
Return the original point that was distorted to this location (inverse of distort).
An abstract base class for all lens distortions.
void vpgl_lens_warp(const vil_image_view< sType > &in, vil_image_view< dType > &out, const vpgl_lens_distortion< T > &ld, InterpFunctor interp)
A version of vil_warp specialized for lens warping with iterative undistort.
vil_image_view< dType > vpgl_lens_unwarp_resize(const vil_image_view< sType > &in, dType, vpgl_lens_distortion< T > &ld, InterpFunctor interp)
A warping function to apply lens distortion to an image.
vgl_box_2d< BoxT > vpgl_lens_unwarp_bounds(const vpgl_lens_distortion< DataT > &lens, const vgl_box_2d< BoxT > &box, BoxT step_size=BoxT(1))
Compute a bounding box for an existing box in the distorted space.
vil_image_view< dType > vpgl_lens_warp_resize(const vil_image_view< sType > &in, dType, vpgl_lens_distortion< T > &ld, InterpFunctor interp)
A warping function to apply lens distortion to an image.
virtual vgl_homg_point_2d< T > distort(const vgl_homg_point_2d< T > &point) const =0
Distort a projected point on the image plane.
void add(vgl_point_2d< Type > const &p)
vgl_box_2d< BoxT > vpgl_lens_warp_bounds(const vpgl_lens_distortion< DataT > &lens, const vgl_box_2d< BoxT > &box, BoxT step_size=BoxT(1))
Compute a bounding box in the distorted space for an existing box.
void bounds(vbl_array_1d< T > const &in, T &min, T &max)
forward declare vgl_homg_point_2d<T> and vgl_vector_2d<T>.
virtual void set_translation(const vgl_vector_2d< T > &offset, bool after=true)=0
Set a translation to apply before of after distortion.
void vpgl_lens_unwarp(const vil_image_view< sType > &in, vil_image_view< dType > &out, const vpgl_lens_distortion< T > &ld, InterpFunctor interp)
A version of vil_warp specialized for lens unwarping.