contrib/mul/vimt3d/vimt3d_resample_tricubic.h
Go to the documentation of this file.
00001 // This is mul/vimt3d/vimt3d_resample_tricubic.h
00002 #ifndef vimt3d_resample_tricubic_h_
00003 #define vimt3d_resample_tricubic_h_
00004 //:
00005 // \file
00006 // \brief Resample a 3D image by a different factor in each dimension
00007 // \author Gwenael Guillard
00008 
00009 #include <vgl/vgl_point_3d.h>
00010 #include <vgl/vgl_vector_3d.h>
00011 #include <vil3d/vil3d_image_view.h>
00012 #include <vil3d/algo/vil3d_gauss_reduce.h>
00013 #include <vil3d/vil3d_resample_tricubic.h>
00014 #include <vimt3d/vimt3d_image_3d_of.h>
00015 
00016 //: Sample grid of points in one image and place in another, using tricubic interpolation.
00017 //  dest_image(i,j,k,p) is sampled from the src_image at p+i.u+j.v+k.w,
00018 //  where i=[0..n1-1], j=[0..n2-1], k=[0..n3-1] in world co-ordinates.
00019 //
00020 //  dest_image resized to (n1,n2,n3,src_image.nplanes())
00021 //
00022 //  dest_image.world2im() set up so that the world co-ordinates in src and dest match
00023 //
00024 //  Points outside image return zero or \a outval
00025 template <class sType, class dType>
00026 inline void vimt3d_resample_tricubic(
00027   const vimt3d_image_3d_of<sType>& src_image,
00028   vimt3d_image_3d_of<dType>& dest_image,
00029   const vgl_point_3d<double>& p,
00030   const vgl_vector_3d<double>& u,
00031   const vgl_vector_3d<double>& v,
00032   const vgl_vector_3d<double>& w,
00033   int n1, int n2, int n3,
00034   dType outval=0)
00035 {
00036   const vimt3d_transform_3d& s_w2i = src_image.world2im();
00037   vgl_point_3d<double> im_p = s_w2i(p);
00038   vgl_vector_3d<double> im_u = s_w2i.delta(p, u);
00039   vgl_vector_3d<double> im_v = s_w2i.delta(p, v);
00040   vgl_vector_3d<double> im_w = s_w2i.delta(p, w);
00041 
00042   vil3d_resample_tricubic(src_image.image(),dest_image.image(),
00043                            im_p.x(), im_p.y(), im_p.z(),
00044                            im_u.x(), im_u.y(), im_u.z(),
00045                            im_v.x(), im_v.y(), im_v.z(),
00046                            im_w.x(), im_w.y(), im_w.z(),
00047                            n1, n2, n3,
00048                            outval);
00049 
00050   // Point (i,j,k) in dest corresponds to p+i.u+j.v+k.w,
00051   // an affine transformation for image to world
00052   vimt3d_transform_3d d_i2w;
00053   d_i2w.set_affine(p,u,v,w);
00054   d_i2w.simplify();
00055   dest_image.set_world2im(d_i2w.inverse());
00056 }
00057 
00058 
00059 //: Sample grid of points in one image and place in another, using tricubic interpolation.
00060 //  dest_image(i,j,k,p) is sampled from the src_image at
00061 //  p+i.u+j.v+k.w, where i=[0..nk-1], j=[0..nj-1], k=[0..nk-1] in world co-ordinates.
00062 //
00063 //  dest_image resized to (ni,nj,nk,src_image.nplanes())
00064 //
00065 //  dest_image.world2im() set up so that the world co-ordinates in src and dest match
00066 //
00067 //  Points outside image return the value of the nearest valid pixel.
00068 // \relatesalso vimt3d_image_3d_of
00069 template <class sType, class dType>
00070 inline void vimt3d_resample_tricubic_edge_extend(
00071   const vimt3d_image_3d_of<sType>& src_image,
00072   vimt3d_image_3d_of<dType>& dest_image,
00073   const vgl_point_3d<double>& p,
00074   const vgl_vector_3d<double>& u,
00075   const vgl_vector_3d<double>& v,
00076   const vgl_vector_3d<double>& w,
00077   int ni, int nj, int nk)
00078 {
00079   const vimt3d_transform_3d& s_w2i = src_image.world2im();
00080   vgl_point_3d<double> im_p = s_w2i(p);
00081   vgl_vector_3d<double> im_u = s_w2i.delta(p, u);
00082   vgl_vector_3d<double> im_v = s_w2i.delta(p, v);
00083   vgl_vector_3d<double> im_w = s_w2i.delta(p, w);
00084 
00085   vil3d_resample_tricubic_edge_extend(src_image.image(),dest_image.image(),
00086     im_p.x(),im_p.y(),im_p.z(), im_u.x(),im_u.y(),im_u.z(),
00087     im_v.x(),im_v.y(),im_v.z(), im_w.x(),im_w.y(),im_w.z(), ni,nj,nk);
00088 
00089   // Point (i,j,k) in dest corresponds to p+i.u+j.v+k.w,
00090   // an affine transformation for image to world
00091   vimt3d_transform_3d d_i2w;
00092   d_i2w.set_affine(p,u,v,w);
00093   d_i2w.simplify();
00094   dest_image.set_world2im(d_i2w.inverse());
00095 }
00096 
00097 
00098 #endif // vimt3d_resample_tricubic_h_