00001 #ifndef vimt_resample_bilin_h_
00002 #define vimt_resample_bilin_h_
00003
00004
00005
00006
00007
00008 #include <vcl_cassert.h>
00009 #include <vil/vil_resample_bilin.h>
00010 #include <vil/algo/vil_gauss_reduce.h>
00011 #include <vimt/vimt_image_2d_of.h>
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 template <class sType, class dType>
00024 inline void vimt_resample_bilin(
00025 const vimt_image_2d_of<sType>& src_image,
00026 vimt_image_2d_of<dType>& dest_image,
00027 const vgl_point_2d<double>& p,
00028 const vgl_vector_2d<double>& u,
00029 const vgl_vector_2d<double>& v,
00030 int n1, int n2)
00031 {
00032
00033 assert(src_image.world2im().form()!=vimt_transform_2d::Projective);
00034
00035 const vimt_transform_2d& s_w2i = src_image.world2im();
00036 vgl_point_2d<double> im_p = s_w2i(p);
00037 vgl_vector_2d<double> im_u = s_w2i.delta(p, u);
00038 vgl_vector_2d<double> im_v = s_w2i.delta(p, v);
00039
00040 vil_resample_bilin(src_image.image(),dest_image.image(),
00041 im_p.x(),im_p.y(), im_u.x(),im_u.y(),
00042 im_v.x(),im_v.y(), n1,n2);
00043
00044
00045
00046 vimt_transform_2d d_i2w;
00047 d_i2w.set_affine(p,u,v);
00048 dest_image.set_world2im(d_i2w.inverse());
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template <class sType, class dType>
00063 inline void vimt_resample_bilin_edge_extend(
00064 const vimt_image_2d_of<sType>& src_image,
00065 vimt_image_2d_of<dType>& dest_image,
00066 const vgl_point_2d<double>& p,
00067 const vgl_vector_2d<double>& u,
00068 const vgl_vector_2d<double>& v,
00069 int n1, int n2)
00070 {
00071
00072 assert(src_image.world2im().form()!=vimt_transform_2d::Projective);
00073
00074 const vimt_transform_2d& s_w2i = src_image.world2im();
00075 vgl_point_2d<double> im_p = s_w2i(p);
00076 vgl_vector_2d<double> im_u = s_w2i.delta(p, u);
00077 vgl_vector_2d<double> im_v = s_w2i.delta(p, v);
00078
00079 vil_resample_bilin_edge_extend(src_image.image(),dest_image.image(),
00080 im_p.x(),im_p.y(), im_u.x(),im_u.y(),
00081 im_v.x(),im_v.y(), n1,n2);
00082
00083
00084
00085 vimt_transform_2d d_i2w;
00086 d_i2w.set_affine(p,u,v);
00087 dest_image.set_world2im(d_i2w.inverse());
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template <class sType, class dType>
00102 inline void vimt_resample_bilin_smoothing(
00103 const vimt_image_2d_of<sType>& src_image,
00104 vimt_image_2d_of<dType>& dest_image,
00105 const vgl_point_2d<double>& p,
00106 const vgl_vector_2d<double>& u,
00107 const vgl_vector_2d<double>& v,
00108 int n1, int n2)
00109 {
00110
00111 assert(src_image.world2im().form()!=vimt_transform_2d::Projective);
00112
00113 vimt_transform_2d scaling;
00114 scaling.set_zoom_only(0.5,0,0);
00115
00116 vimt_image_2d_of<sType> im = src_image;
00117 vgl_vector_2d<double> im_d = im.world2im().delta(p, u) + im.world2im().delta(p, v);
00118
00119
00120
00121
00122
00123 while (im_d.length() > 1.33*1.414 && im.image().ni() > 5 && im.image().nj() > 5)
00124 {
00125 vimt_image_2d_of<sType> dest;
00126 vil_image_view<sType> work;
00127 vil_gauss_reduce(im.image(), dest.image(), work);
00128
00129 dest.set_world2im(scaling * im.world2im());
00130
00131
00132 im = dest;
00133 im_d = im.world2im().delta(p, u) + im.world2im().delta(p, v);
00134 }
00135
00136 vimt_resample_bilin_edge_extend(im, dest_image, p, u, v, n1, n2);
00137 }
00138
00139 #endif // vimt_resample_bilin_h_