2 #ifndef vil_resample_nearest_hxx_ 3 #define vil_resample_nearest_hxx_ 21 #pragma warning( disable : 4800 ) 31 && y0+1 <= image.
nj();
40 template <
class sType,
class dType>
43 double x0,
double y0,
double dx1,
double dy1,
44 double dx2,
double dy2,
int n1,
int n2)
50 y0+(n1-1)*dy1+(n2-1)*dy2,src_image);
53 std::cout<<
"src_image= "<<src_image<<std::endl
54 <<
"x0="<<x0<<std::endl
55 <<
"y0="<<y0<<std::endl
56 <<
"x0+(n1-1)*dx1+(n2-1)*dx2="<<x0+(n1-1)*dx1+(n2-1)*dx2<<std::endl
57 <<
"y0+(n1-1)*dy1+(n2-1)*dy2="<<y0+(n1-1)*dy1+(n2-1)*dy2<<std::endl;
60 const unsigned ni = src_image.
ni();
61 const unsigned nj = src_image.
nj();
62 const unsigned np = src_image.
nplanes();
63 const std::ptrdiff_t istep = src_image.
istep();
64 const std::ptrdiff_t jstep = src_image.
jstep();
65 const std::ptrdiff_t pstep = src_image.
planestep();
69 const std::ptrdiff_t d_istep = dest_image.
istep();
70 const std::ptrdiff_t d_jstep = dest_image.
jstep();
71 const std::ptrdiff_t d_pstep = dest_image.
planestep();
81 dType *row = d_plane0;
82 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
86 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
92 dType *row = d_plane0;
93 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
97 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
99 for (
unsigned int p=0;p<np;++p)
110 dType *row = d_plane0;
111 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
115 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
122 dType *row = d_plane0;
123 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
127 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
129 for (
unsigned int p=0;p<np;++p)
140 template <
class sType,
class dType>
148 double dx1=f*(src_image.
ni()-1)*1.0/(n1-1);
151 double dy2=f*(src_image.
nj()-1)*1.0/(n2-1);
162 template <
class sType,
class dType>
166 double x0,
double y0,
double dx1,
double dy1,
167 double dx2,
double dy2,
int n1,
int n2)
173 y0+(n1-1)*dy1+(n2-1)*dy2,src_image);
176 std::cout<<
"src_image= "<<src_image<<std::endl
177 <<
"x0="<<x0<<std::endl
178 <<
"y0="<<y0<<std::endl
179 <<
"x0+(n1-1)*dx1+(n2-1)*dx2="<<x0+(n1-1)*dx1+(n2-1)*dx2<<std::endl
180 <<
"y0+(n1-1)*dy1+(n2-1)*dy2="<<y0+(n1-1)*dy1+(n2-1)*dy2<<std::endl;
183 const unsigned ni = src_image.
ni();
184 const unsigned nj = src_image.
nj();
185 const unsigned np = src_image.
nplanes();
186 const std::ptrdiff_t istep = src_image.
istep();
187 const std::ptrdiff_t jstep = src_image.
jstep();
188 const std::ptrdiff_t pstep = src_image.
planestep();
192 const std::ptrdiff_t d_istep = dest_image.
istep();
193 const std::ptrdiff_t d_jstep = dest_image.
jstep();
194 const std::ptrdiff_t d_pstep = dest_image.
planestep();
204 dType *row = d_plane0;
205 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
209 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
215 dType *row = d_plane0;
216 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
220 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
222 for (
unsigned int p=0;p<np;++p)
233 dType *row = d_plane0;
234 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
238 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
240 x,y,plane0,ni,nj,istep,jstep);
245 dType *row = d_plane0;
246 for (
int j=0;j<n2;++j,x1+=dx2,y1+=dy2,row+=d_jstep)
250 for (
int i=0;i<n1;++i,x+=dx1,y+=dy1,dpt+=d_istep)
252 for (
unsigned int p=0;p<np;++p)
254 x,y,plane0+p*pstep,ni,nj,istep,jstep);
263 template <
class sType,
class dType>
271 double dx1=f*(src_image.
ni()-1)*1.0/(n1-1);
274 double dy2=f*(src_image.
nj()-1)*1.0/(n2-1);
276 src_image, dest_image, x0, y0, dx1, dy1, dx2, dy2, n1, n2 );
278 #define VIL_RESAMPLE_NEAREST_INSTANTIATE( sType, dType ) \ 279 template void vil_resample_nearest(const vil_image_view<sType >& src_image, \ 280 vil_image_view<dType >& dest_image, \ 281 double x0, double y0, double dx1, double dy1, \ 282 double dx2, double dy2, int n1, int n2); \ 283 template void vil_resample_nearest(const vil_image_view<sType >& src_image, \ 284 vil_image_view<dType >& dest_image, \ 286 template void vil_resample_nearest_edge_extend(const vil_image_view<sType >& src_image, \ 287 vil_image_view<dType >& dest_image, \ 288 double x0, double y0, double dx1, double dy1, \ 289 double dx2, double dy2, int n1, int n2); \ 290 template void vil_resample_nearest_edge_extend(const vil_image_view<sType >& src_image, \ 291 vil_image_view<dType >& dest_image, \ 294 #endif // vil_resample_nearest_hxx_ An abstract base class of smart pointers to actual image data in memory.
Concrete view of image data of type T held in memory.
void vil_resample_nearest(const vil_image_view< sType > &src_image, vil_image_view< dType > &dest_image, double x0, double y0, double dx1, double dy1, double dx2, double dy2, int n1, int n2)
Sample grid of points in one image and place in another, using nearest neighbour interpolation.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
Sample image with nearest neighbour interpolation in one image and place in another.
T vil_nearest_interp_unsafe(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute nearest neighbour interpolation at (x,y), no bound checks. Requires -0.5<=x<ni-0....
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
bool vil_resample_nearest_corner_in_image(double x0, double y0, const vil_image_view_base &image)
This function should not be the same in nearest, bicub and bilin.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
T vil_nearest_interp_safe_extend(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute nearest neighbour interpolation at (x,y), with bound checks.
T vil_nearest_interp(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute nearest neighbour interpolation at (x,y), with minimal bound checks.
void vil_resample_nearest_edge_extend(const vil_image_view< sType > &src_image, vil_image_view< dType > &dest_image, double x0, double y0, double dx1, double dy1, double dx2, double dy2, int n1, int n2)
Sample grid of points in one image and place in another, using nearest neighbour interpolation.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
nearest neighbour interpolation functions for 2D images
T vil_nearest_interp_safe(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute nearest neighbour interpolation at (x,y), with bound checks.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.