2 #ifndef vil_gauss_reduce_hxx_ 3 #define vil_gauss_reduce_hxx_ 12 # include <vcl_msvc_warnings.h> 26 unsigned ni = src_im.
ni();
27 unsigned nj = src_im.
nj();
28 unsigned n_planes = src_im.
nplanes();
31 unsigned ni2 = (ni+1)/2;
32 unsigned nj2 = (nj+1)/2;
36 if (work_im.
ni()<ni2 || work_im.
nj()<nj)
40 for (
unsigned int i=0;i<n_planes;++i)
64 unsigned ni = src_im.
ni();
65 unsigned nj = src_im.
nj();
66 unsigned n_planes = src_im.
nplanes();
69 unsigned ni2 = (2*ni+1)/3;
70 unsigned nj2 = (2*nj+1)/3;
74 if (work_im.
ni()<ni2 || work_im.
nj()<nj)
78 for (
unsigned int i=0;i<n_planes;++i)
100 unsigned int ni = src_im.
ni();
101 unsigned int nj = src_im.
nj();
102 unsigned int n_planes = src_im.
nplanes();
105 unsigned int ni2 = (ni+1)/2;
106 unsigned int nj2 = (nj+1)/2;
111 for (
unsigned int i=0;i<n_planes;++i)
123 inline unsigned char rl_round(
double x,
unsigned char )
124 {
return (
unsigned char) (x+0.5);}
126 inline signed char rl_round(
double x,
signed char )
127 {
return (
signed char) (x+0.5);}
129 inline unsigned short rl_round(
double x,
unsigned short )
130 {
return (
unsigned short) (x+0.5);}
132 inline signed short rl_round(
double x,
signed short )
133 {
return (
signed short) (x+0.5);}
135 inline unsigned int rl_round(
double x,
unsigned int )
136 {
return (
unsigned int) (x+0.5);}
139 {
return (
signed int) (x+0.5);}
141 inline unsigned long rl_round(
double x,
unsigned long )
142 {
return (
unsigned long) (x+0.5);}
144 inline signed long rl_round(
double x,
signed long )
145 {
return (
signed long) (x+0.5);}
151 {
return (
float) x; }
166 assert(src.
ni() >= 5 && src.
nj() >= 5);
171 for (
unsigned y=0;y<src.
nj();y++)
173 unsigned ni2 = src.
ni()-2;
174 for (
unsigned x=2;x<ni2;++x)
175 worka(x,y) =
rl_round( params.
filt2() * (src(x-2,y) + src(x+2,y))
176 + params.
filt1() * (src(x-1,y) + src(x+1,y))
177 + params.
filt0() * src(x ,y),
202 for (
unsigned int y=2;y+2<src.
nj();++y)
204 for (
unsigned int x=0; x<src.
ni(); x++)
205 workb(x,y) =
rl_round( params.
filt2() *(worka(x,y-2) + worka(x,y+2))
206 + params.
filt1() *(worka(x,y-1) + worka(x,y+1))
207 + params.
filt0() * worka(x, y),
213 for (
unsigned x=0;x<src.
ni();x++)
239 const double init_x = 0.5 * (src.
ni()-1 - (dest.
ni()-1)*params.
scale_step());
240 double yd = 0.5 * (src.
nj() -1 - (dest.
nj()-1)*params.
scale_step());
241 for (
unsigned int yi=0; yi<dest.
nj(); yi++)
244 for (
unsigned int xi=0; xi<dest.
ni(); xi++)
261 if (worka.
ni() < src.
ni() || worka.
nj() < src.
nj())
263 if (workb.
ni() < src.
ni() || workb.
nj() < src.
nj())
269 for (
unsigned p=0;p<src.
nplanes();++p) {
275 vsl_indent_inc(std::cout);
276 std::cout << vsl_indent() <<
"Work image B\n";
277 workb_.print_all(std::cout);
278 vsl_indent_dec(std::cout);
285 unsigned src_ni,
unsigned src_nj,
286 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
288 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
291 const T* s_row = src_im;
292 std::ptrdiff_t sxs2 = s_x_step*2;
293 unsigned ni2 = (src_ni-3)/2;
296 for (
unsigned y=0;y<src_nj;++y)
299 double dsum = 0.071 * static_cast<double>(s_row[sxs2]) +
300 0.357 * static_cast<double>(s_row[s_x_step]) +
301 0.572 * static_cast<double>(s_row[0]);
302 rounder(dsum, *d_row);
304 T* d = d_row + d_x_step;
305 const T* s = s_row + sxs2;
306 for (
unsigned x=0;x<ni2;++x)
308 dsum = 0.05*static_cast<double>(s[-sxs2]) + 0.25*static_cast<double>(s[-s_x_step]) +
309 0.05*static_cast<double>(s[ sxs2]) + 0.25*static_cast<double>(s[ s_x_step]) +
310 0.4 *static_cast<double>(s[0]);
317 dsum = 0.071 * static_cast<double>(s[-sxs2]) +
318 0.357 * static_cast<double>(s[-s_x_step]) +
319 0.572 * static_cast<double>(s[0]);
332 unsigned src_ni,
unsigned src_nj,
333 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
335 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
337 std::ptrdiff_t sxs2 = s_x_step*2;
338 std::ptrdiff_t sys2 = s_y_step*2;
339 T* d_row = dest_im+d_y_step;
340 const T* s_row1 = src_im + s_y_step;
341 const T* s_row2 = s_row1 + s_y_step;
342 const T* s_row3 = s_row2 + s_y_step;
343 unsigned ni2 = (src_ni-2)/2;
344 unsigned nj2 = (src_nj-2)/2;
347 for (
unsigned y=0;y<nj2;++y)
351 T * d = d_row + d_x_step;
352 const T* s1 = s_row1 + sxs2;
353 const T* s2 = s_row2 + sxs2;
354 const T* s3 = s_row3 + sxs2;
355 for (
unsigned x=0;x<ni2;++x)
358 double ds1 = 0.0625 * static_cast<double>(s1[-s_x_step])
359 + 0.125 * static_cast<double>(s1[0])
360 + 0.0625 * static_cast<double>(s1[s_x_step]),
361 ds2 = 0.1250 * static_cast<double>(s2[-s_x_step])
362 + 0.250 * static_cast<double>(s2[0])
363 + 0.1250 * static_cast<double>(s2[s_x_step]),
364 ds3 = 0.0625 * static_cast<double>(s3[-s_x_step])
365 + 0.125 * static_cast<double>(s3[0])
366 + 0.0625 * static_cast<double>(s3[s_x_step]);
367 rounder(ds1 + ds2 + ds3, *d);
387 const T* s0 = src_im;
388 unsigned ni=(src_ni+1)/2;
389 for (
unsigned i=0;i<ni;++i)
397 unsigned yhi = (src_nj-1)/2;
398 T* dest_last_row = dest_im + yhi*d_y_step;
399 const T* s_last = src_im + yhi*sys2;
400 for (
unsigned i=0;i<ni;++i)
402 dest_last_row[i]= *s_last;
411 unsigned src_ni,
unsigned src_nj,
412 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
413 T* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
416 const T* s_row = src_im;
417 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
418 unsigned d_ni = (2*src_ni+1)/3;
419 unsigned d_ni2 = d_ni/2;
422 for (
unsigned y=0;y<src_nj;++y)
426 double drow0=0.75*static_cast<double>(s_row[0]) + 0.25*static_cast<double>(s_row[s_x_step]);
427 double drow_xs=0.5*static_cast<double>(s_row[s_x_step]) + 0.5*static_cast<double>(s_row[sxs2]);
428 rounder(drow0,d_row[0]);
429 rounder(drow_xs,d_row[d_x_step]);
431 T* d = d_row + 2*d_x_step;
432 const T* s = s_row + sxs3;
433 for (
unsigned x=1;x<d_ni2;++x)
435 double df= 0.2 * ( static_cast<double>(s[-s_x_step]) + static_cast<double>(s[s_x_step]) )
436 + 0.6 * static_cast<double>(s[0]) ;
441 df = 0.5*(static_cast<double>(s[s_x_step]) + static_cast<double>(s[sxs2]) );
450 double df=0.75*static_cast<double>(s[-s_x_step]) + 0.25*static_cast<double>(s[0]);
453 else if (src_ni%3==2)
455 double df = 0.2 * (static_cast<double>(s[-s_x_step]) + static_cast<double>(s[s_x_step]) )
456 + 0.6 * static_cast<double>(s[0]);
465 #undef VIL_GAUSS_REDUCE_INSTANTIATE 466 #define VIL_GAUSS_REDUCE_INSTANTIATE(T) \ 467 template void vil_gauss_reduce(const vil_image_view<T >& src, \ 468 vil_image_view<T >& dest, \ 469 vil_image_view<T >& work_im); \ 470 template void vil_gauss_reduce_2_3(const vil_image_view<T >& src, \ 471 vil_image_view<T >& dest, \ 472 vil_image_view<T >& work_im); \ 473 template void vil_gauss_reduce_121(const vil_image_view<T >& src, \ 474 vil_image_view<T >& dest); \ 475 template void vil_gauss_reduce_general(const vil_image_view<T >& src_im, \ 476 vil_image_view<T >& dest_im, \ 477 vil_image_view<T >& worka, \ 478 vil_image_view<T >& workb, \ 479 const vil_gauss_reduce_params& params) 481 #endif // vil_gauss_reduce_hxx_ double filt0() const
Filter tap value.
void vil_gauss_reduce_general(const vil_image_view< T > &src_im, vil_image_view< T > &dest_im, const vil_gauss_reduce_params ¶ms)
Smooth and subsample src_im by an arbitrary factor to produce dest_im.
void vil_gauss_reduce_2_3_1plane(const T *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, T *dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
Smooth and subsample single plane src_im in x, result is 2/3rd size.
void vil_gauss_reduce_121_1plane(const T *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, T *dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y.
Concrete view of image data of type T held in memory.
double scale_step() const
the scale step between pyramid levels.
void vil_gauss_reduce_1plane(const T *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, T *dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
Smooth and subsample single plane src_im in x to produce dest_im.
void vil_gauss_reduce_121(const vil_image_view< T > &src, vil_image_view< T > &dest)
Smooth and subsample src_im to produce dest_im.
double filt_pen_edge1() const
Filter tap value.
double filt_pen_edge0() const
Filter tap value.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
void vil_gauss_reduce_2_3(const vil_image_view< T > &src_im, vil_image_view< T > &dest_im, vil_image_view< T > &work_im)
Smooth and subsample src_im to produce dest_im (2/3 size).
double filt_pen_edge_n1() const
Filter tap value.
Some standard conversion functions.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
double filt1() const
Filter tap value.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
Performs rounding between different pixel types.
double vil_bilin_interp_safe_extend(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute bilinear interpolation at (x,y), with bound checks.
void vil_gauss_reduce(const vil_image_view< T > &src, vil_image_view< T > &dest, vil_image_view< T > &work_im)
Smooth and subsample src_im to produce dest_im.
double filt_edge2() const
Filter tap value.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
vil_image_view< T > vil_plane(const vil_image_view< T > &im, unsigned p)
Return a view of im's plane p.
Functions to smooth and sub-sample image in one direction.
unsigned nplanes() const
Number of planes.
double filt2() const
Filter tap value.
double filt_pen_edge2() const
Filter tap value.
unsigned char rl_round(double x, unsigned char)
An optimisable rounding function.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
double filt_edge1() const
Filter tap value.
double filt_edge0() const
Filter tap value.
void vil_gauss_reduce_general_plane(const vil_image_view< T > &src, vil_image_view< T > &dest, vil_image_view< T > &worka, vil_image_view< T > &workb, const vil_gauss_reduce_params ¶ms)
Smooth and subsample src_im to produce dest_im.
Bilinear interpolation functions for 2D images.