1 // This is mul/vil3d/vil3d_resample_trilinear.h
2 #ifndef vil3d_resample_trilinear_h_
3 #define vil3d_resample_trilinear_h_
4 
5 //:
6 // \file
7 // \brief Resample a 3D image by a different factor in each dimension
8 // \author Kevin de Souza, Ian Scott
9 
10 #include <vil3d/vil3d_image_view.h>
11 
12 
13 //: Sample grid of points in one image and place in another, using trilinear interpolation.
14 //  dest_image(i,j,k,p) is sampled from the src_image at
15 //  (x0+i.dx1+j.dx2+k.dx3, y0+i.dy1+j.dy2+k.dy3, z0+i.dz1+j.dz2+k.dz3),
16 //  where i=[0..n1-1], j=[0..n2-1], k=[0..n3-1].
17 //  dest_image resized to (n1,n2,n3,src_image.nplanes())
18 //  Points outside image return zero or \a outval
19 template <class S, class T>
20 void vil3d_resample_trilinear(const vil3d_image_view<S>& src_image,
21                               vil3d_image_view<T>& dest_image,
22                               double x0, double y0, double z0,
23                               double dx1, double dy1, double dz1,
24                               double dx2, double dy2, double dz2,
25                               double dx3, double dy3, double dz3,
26                               int n1, int n2, int n3,
27                               T outval=0, double edge_tol=0);
28 
29 
30 //: Sample grid of points in one image and place in another, using trilinear interpolation and edge extension.
31 //  dest_image(i,j,k,p) is sampled from the src_image at
32 //  (x0+i.dx1+j.dx2+k.dx3, y0+i.dy1+j.dy2+k.dy3, z0+i.dz1+j.dz2+k.dz3),
33 //  where i=[0..n1-1], j=[0..n2-1], k=[0..n3-1].
34 //  dest_image resized to (n1,n2,n3,src_image.nplanes())
35 //  Points outside src_image return the value of the nearest valid pixel.
36 template <class S, class T>
37 void vil3d_resample_trilinear_edge_extend(const vil3d_image_view<S>& src_image,
38                                           vil3d_image_view<T>& dest_image,
39                                           double x0, double y0, double z0,
40                                           double dx1, double dy1, double dz1,
41                                           double dx2, double dy2, double dz2,
42                                           double dx3, double dy3, double dz3,
43                                           int n1, int n2, int n3);
44 
45 
46 //: Resample image to a specified dimensions (n1 * n2 * n3)
47 template <class S, class T>
48 void vil3d_resample_trilinear(const vil3d_image_view<S>& src_image,
49                               vil3d_image_view<T>& dest_image,
50                               int n1, int n2, int n3);
51 
52 
53 //: Resample a 3D image by a different factor in each dimension.
54 //  \p dst_image resized by factors \p dx, \p dy, \p dz.
55 // \note The upper image boundaries are extended.
56 // \param dx Scaling factor >1
57 // \param dy Scaling factor >1
58 // \param dz Scaling factor >1
59 //  dst_image(i, j, k, p) is sampled from src_image(i/dx, j/dy, k/dz, p).
60 // Interpolated values are rounded when the type T is smaller than double.
61 template <class T>
62 void vil3d_resample_trilinear(const vil3d_image_view<T>& src_image,
63                               vil3d_image_view<T>& dst_image,
64                               const double dx,
65                               const double dy,
66                               const double dz);
67 
68 //: Resample a 3D image by a factor of 2 in each dimension.
69 // \p dst_image is resized to 2*src_image.n?()-1 in each direction.
70 // Interpolated values are truncated when the type T is smaller than double.
71 template <class T>
72 void vil3d_resample_trilinear_scale_2(
73   const vil3d_image_view<T>& src_image,
74   vil3d_image_view<T>& dst_image);
75 
76 #endif // vil3d_resample_trilinear_h_
77