10 # include <vcl_msvc_warnings.h> 13 #include <vxl_config.h> 23 unsigned src_ni,
unsigned src_nj,
24 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
26 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
28 vxl_byte* d_row = dest_im;
29 const vxl_byte* s_row = src_im;
30 std::ptrdiff_t sxs2 = s_x_step*2;
31 unsigned ni2 = (src_ni-3)/2;
32 for (
unsigned y=0;y<src_nj;++y)
35 *d_row = static_cast<vxl_byte>(
37 + 0.357f * s_row[s_x_step]
38 + 0.572f * s_row[0]));
40 vxl_byte * d = d_row + d_x_step;
41 const vxl_byte* s = s_row + sxs2;
42 for (
unsigned x=0;x<ni2;++x)
44 *d = static_cast<vxl_byte>(
46 + 0.25*s[-s_x_step]+ 0.25*s[s_x_step]
53 *d = static_cast<vxl_byte>(
55 + 0.357f * s[-s_x_step]
68 unsigned src_ni,
unsigned src_nj,
69 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
70 float* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
72 float* d_row = dest_im;
73 const float* s_row = src_im;
74 std::ptrdiff_t sxs2 = s_x_step*2;
75 unsigned ni2 = (src_ni-3)/2;
76 for (
unsigned y=0;y<src_nj;++y)
79 *d_row = 0.071f * s_row[sxs2]
80 + 0.357f * s_row[s_x_step]
82 float * d = d_row + d_x_step;
83 const float* s = s_row + sxs2;
84 for (
unsigned x=0;x<ni2;++x)
86 *d = 0.05f*(s[-sxs2] + s[sxs2])
87 + 0.25f*(s[-s_x_step]+ s[s_x_step])
94 *d = 0.071f * s[-sxs2]
95 + 0.357f * s[-s_x_step]
109 unsigned src_ni,
unsigned src_nj,
110 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
111 double* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
113 double* d_row = dest_im;
114 const double* s_row = src_im;
115 std::ptrdiff_t sxs2 = s_x_step*2;
116 unsigned ni2 = (src_ni-3)/2;
117 for (
unsigned y=0;y<src_nj;++y)
120 *d_row = 0.071 * s_row[sxs2]
121 + 0.357 * s_row[s_x_step]
123 double * d = d_row + d_x_step;
124 const double* s = s_row + sxs2;
125 for (
unsigned x=0;x<ni2;++x)
127 *d = 0.05f*(s[-sxs2] + s[sxs2])
128 + 0.25f*(s[-s_x_step]+ s[s_x_step])
135 *d = 0.071f * s[-sxs2]
136 + 0.357f * s[-s_x_step]
149 unsigned src_ni,
unsigned src_nj,
150 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
152 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
154 int* d_row = dest_im;
155 const int* s_row = src_im;
156 std::ptrdiff_t sxs2 = s_x_step*2;
157 unsigned ni2 = (src_ni-3)/2;
158 for (
unsigned y=0;y<src_nj;++y)
162 + 0.357f * s_row[s_x_step]
163 + 0.572f * s_row[0]);
165 int * d = d_row + d_x_step;
166 const int* s = s_row + sxs2;
167 for (
unsigned x=0;x<ni2;++x)
170 0.05*s[ sxs2] + 0.25*s[ s_x_step] +
178 + 0.357f * s[-s_x_step]
191 unsigned src_ni,
unsigned src_nj,
192 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
194 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
196 vxl_int_16* d_row = dest_im;
197 const vxl_int_16* s_row = src_im;
198 std::ptrdiff_t sxs2 = s_x_step*2;
199 unsigned ni2 = (src_ni-3)/2;
200 for (
unsigned y=0;y<src_nj;++y)
203 *d_row = static_cast<vxl_int_16>(
205 + 0.357f * s_row[s_x_step]
206 + 0.572f * s_row[0]));
208 vxl_int_16 * d = d_row + d_x_step;
209 const vxl_int_16* s = s_row + sxs2;
210 for (
unsigned x=0;x<ni2;++x)
213 *d = vxl_int_16(0.5 + 0.05*s[-sxs2] + 0.25*s[-s_x_step]
214 + 0.05*s[ sxs2] + 0.25*s[ s_x_step]
221 *d = static_cast<vxl_int_16>(
223 + 0.357f * s[-s_x_step]
238 unsigned src_ni,
unsigned src_nj,
239 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
240 float* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
242 float* d_row = dest_im;
243 const float* s_row = src_im;
244 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
245 unsigned d_ni = (2*src_ni+1)/3;
246 unsigned d_ni2 = d_ni/2;
247 for (
unsigned y=0;y<src_nj;++y)
250 d_row[0] = 0.75f*s_row[0] + 0.25f*s_row[s_x_step];
251 d_row[d_x_step] = 0.5f*s_row[s_x_step] + 0.5f*s_row[sxs2];
252 float * d = d_row + 2*d_x_step;
253 const float* s = s_row + sxs3;
254 for (
unsigned x=1;x<d_ni2;++x)
256 *d = 0.2f*(s[-s_x_step] + s[s_x_step])+0.6f*s[0];
258 *d = 0.5f*(s[s_x_step] + s[sxs2]);
263 if (src_ni%3==1) *d=0.75f*s[-s_x_step] + 0.25f*s[0];
265 if (src_ni%3==2) *d=0.2f*(s[-s_x_step] + s[s_x_step])+0.6f*s[0];
279 unsigned src_ni,
unsigned src_nj,
280 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
281 double* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
283 double* d_row = dest_im;
284 const double* s_row = src_im;
285 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
286 unsigned d_ni = (2*src_ni+1)/3;
287 unsigned d_ni2 = d_ni/2;
288 for (
unsigned y=0;y<src_nj;++y)
291 d_row[0] = 0.75*s_row[0] + 0.25*s_row[s_x_step];
292 d_row[d_x_step] = 0.5*s_row[s_x_step] + 0.5*s_row[sxs2];
293 double * d = d_row + 2*d_x_step;
294 const double* s = s_row + sxs3;
295 for (
unsigned x=1;x<d_ni2;++x)
297 *d = 0.2*(s[-s_x_step] + s[s_x_step])+0.6*s[0];
299 *d = 0.5*(s[s_x_step] + s[sxs2]);
304 if (src_ni%3==1) *d=0.75*s[-s_x_step] + 0.25*s[0];
306 if (src_ni%3==2) *d=0.2*(s[-s_x_step] + s[s_x_step])+0.6*s[0];
320 unsigned src_ni,
unsigned src_nj,
321 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
322 vxl_byte* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
324 vxl_byte* d_row = dest_im;
325 const vxl_byte* s_row = src_im;
326 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
327 unsigned d_ni = (2*src_ni+1)/3;
328 unsigned d_ni2 = d_ni/2;
329 for (
unsigned y=0;y<src_nj;++y)
333 d_row[0] = vxl_byte(0.5f + 0.75f*s_row[0] + 0.25f*s_row[s_x_step]);
334 d_row[d_x_step] = vxl_byte(0.5f + 0.5f*s_row[s_x_step] + 0.5f*s_row[sxs2]);
335 vxl_byte * d = d_row + 2*d_x_step;
336 const vxl_byte* s = s_row + sxs3;
337 for (
unsigned x=1;x<d_ni2;++x)
339 *d = vxl_byte(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
341 *d = vxl_byte(0.5f + 0.5f*(s[s_x_step] + s[sxs2]));
347 *d = vxl_byte(0.5f + 0.75f*s[-s_x_step] + 0.25f*s[0]);
348 else if (src_ni%3==2)
349 *d = vxl_byte(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
364 unsigned src_ni,
unsigned src_nj,
365 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
366 int* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
368 int* d_row = dest_im;
369 const int* s_row = src_im;
370 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
371 unsigned d_ni = (2*src_ni+1)/3;
372 unsigned d_ni2 = d_ni/2;
373 for (
unsigned y=0;y<src_nj;++y)
377 d_row[0] = int(0.5f + 0.75f*s_row[0] + 0.25f*s_row[s_x_step]);
378 d_row[d_x_step] = int(0.5f + 0.5f*s_row[s_x_step] + 0.5f*s_row[sxs2]);
379 int * d = d_row + 2*d_x_step;
380 const int* s = s_row + sxs3;
381 for (
unsigned x=1;x<d_ni2;++x)
383 *d = int(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
385 *d = int(0.5f + 0.5f*(s[s_x_step] + s[sxs2]));
391 *d = int(0.5f + 0.75f*s[-s_x_step] + 0.25f*s[0]);
392 else if (src_ni%3==2)
393 *d = int(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
407 unsigned src_ni,
unsigned src_nj,
408 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
409 vxl_int_16* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
411 vxl_int_16* d_row = dest_im;
412 const vxl_int_16* s_row = src_im;
413 std::ptrdiff_t sxs2 = s_x_step*2,sxs3 = s_x_step*3;
414 unsigned d_ni = (2*src_ni+1)/3;
415 unsigned d_ni2 = d_ni/2;
416 for (
unsigned y=0;y<src_nj;++y)
420 d_row[0] = vxl_int_16(0.5f + 0.75f*s_row[0] + 0.25f*s_row[s_x_step]);
421 d_row[d_x_step] = vxl_int_16(0.5f + 0.5f*s_row[s_x_step] + 0.5f*s_row[sxs2]);
422 vxl_int_16 * d = d_row + 2*d_x_step;
423 const vxl_int_16* s = s_row + sxs3;
424 for (
unsigned x=1;x<d_ni2;++x)
426 *d = vxl_int_16(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
428 *d = vxl_int_16(0.5f + 0.5f*(s[s_x_step] + s[sxs2]));
434 *d = vxl_int_16(0.5f + 0.75f*s[-s_x_step] + 0.25f*s[0]);
435 else if (src_ni%3==2)
436 *d = vxl_int_16(0.5f + 0.2f*(s[-s_x_step] + s[s_x_step]) + 0.6f*s[0]);
447 unsigned src_ni,
unsigned src_nj,
448 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
449 vxl_byte* dest_im, std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
451 std::ptrdiff_t sxs2 = s_x_step*2;
452 std::ptrdiff_t sys2 = s_y_step*2;
453 vxl_byte* d_row = dest_im+d_y_step;
454 const vxl_byte* s_row1 = src_im + s_y_step;
455 const vxl_byte* s_row2 = s_row1 + s_y_step;
456 const vxl_byte* s_row3 = s_row2 + s_y_step;
457 unsigned ni2 = (src_ni-2)/2;
458 unsigned nj2 = (src_nj-2)/2;
459 for (
unsigned y=0;y<nj2;++y)
463 vxl_byte * d = d_row + d_x_step;
464 const vxl_byte* s1 = s_row1 + sxs2;
465 const vxl_byte* s2 = s_row2 + sxs2;
466 const vxl_byte* s3 = s_row3 + sxs2;
467 for (
unsigned x=0;x<ni2;++x)
471 *d = vxl_byte( 0.0625f * s1[-s_x_step] + 0.125f * s1[0] + 0.0625f * s1[s_x_step]
472 + 0.1250f * s2[-s_x_step] + 0.250f * s2[0] + 0.1250f * s2[s_x_step]
473 + 0.0625f * s3[-s_x_step] + 0.125f * s3[0] + 0.0625f * s3[s_x_step] +0.5);
493 const vxl_byte* s0 = src_im;
494 unsigned ni=(src_ni+1)/2;
495 for (
unsigned i=0;i<ni;++i)
503 unsigned yhi = (src_nj-1)/2;
504 vxl_byte* dest_last_row = dest_im + yhi*d_y_step;
505 const vxl_byte* s_last = src_im + yhi*sys2;
506 for (
unsigned i=0;i<ni;++i)
508 dest_last_row[i]= *s_last;
519 unsigned src_ni,
unsigned src_nj,
520 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
522 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
524 std::ptrdiff_t sxs2 = s_x_step*2;
525 std::ptrdiff_t sys2 = s_y_step*2;
526 float* d_row = dest_im+d_y_step;
527 const float* s_row1 = src_im + s_y_step;
528 const float* s_row2 = s_row1 + s_y_step;
529 const float* s_row3 = s_row2 + s_y_step;
530 unsigned ni2 = (src_ni-2)/2;
531 unsigned nj2 = (src_nj-2)/2;
532 for (
unsigned y=0;y<nj2;++y)
536 float * d = d_row + d_x_step;
537 const float* s1 = s_row1 + sxs2;
538 const float* s2 = s_row2 + sxs2;
539 const float* s3 = s_row3 + sxs2;
540 for (
unsigned x=0;x<ni2;++x)
543 *d = 0.0625f * s1[-s_x_step] + 0.125f * s1[0] + 0.0625f * s1[s_x_step]
544 + 0.1250f * s2[-s_x_step] + 0.250f * s2[0] + 0.1250f * s2[s_x_step]
545 + 0.0625f * s3[-s_x_step] + 0.125f * s3[0] + 0.0625f * s3[s_x_step];
565 const float* s0 = src_im;
566 unsigned ni=(src_ni+1)/2;
567 for (
unsigned i=0;i<ni;++i)
575 unsigned yhi = (src_nj-1)/2;
576 float* dest_last_row = dest_im + yhi*d_y_step;
577 const float* s_last = src_im + yhi*sys2;
578 for (
unsigned i=0;i<ni;++i)
580 dest_last_row[i]= *s_last;
591 unsigned src_ni,
unsigned src_nj,
592 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
594 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
596 std::ptrdiff_t sxs2 = s_x_step*2;
597 std::ptrdiff_t sys2 = s_y_step*2;
598 double* d_row = dest_im+d_y_step;
599 const double* s_row1 = src_im + s_y_step;
600 const double* s_row2 = s_row1 + s_y_step;
601 const double* s_row3 = s_row2 + s_y_step;
602 unsigned ni2 = (src_ni-2)/2;
603 unsigned nj2 = (src_nj-2)/2;
604 for (
unsigned y=0;y<nj2;++y)
608 double * d = d_row + d_x_step;
609 const double* s1 = s_row1 + sxs2;
610 const double* s2 = s_row2 + sxs2;
611 const double* s3 = s_row3 + sxs2;
612 for (
unsigned x=0;x<ni2;++x)
615 *d = 0.0625 * s1[-s_x_step] + 0.125 * s1[0] + 0.0625 * s1[s_x_step]
616 + 0.1250 * s2[-s_x_step] + 0.250 * s2[0] + 0.1250 * s2[s_x_step]
617 + 0.0625 * s3[-s_x_step] + 0.125 * s3[0] + 0.0625 * s3[s_x_step];
637 const double* s0 = src_im;
638 unsigned ni=(src_ni+1)/2;
639 for (
unsigned i=0;i<ni;++i)
647 unsigned yhi = (src_nj-1)/2;
648 double* dest_last_row = dest_im + yhi*d_y_step;
649 const double* s_last = src_im + yhi*sys2;
650 for (
unsigned i=0;i<ni;++i)
652 dest_last_row[i]= *s_last;
663 unsigned src_ni,
unsigned src_nj,
664 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
666 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
668 std::ptrdiff_t sxs2 = s_x_step*2;
669 std::ptrdiff_t sys2 = s_y_step*2;
670 int* d_row = dest_im+d_y_step;
671 const int* s_row1 = src_im + s_y_step;
672 const int* s_row2 = s_row1 + s_y_step;
673 const int* s_row3 = s_row2 + s_y_step;
674 unsigned ni2 = (src_ni-2)/2;
675 unsigned nj2 = (src_nj-2)/2;
676 for (
unsigned y=0;y<nj2;++y)
680 int * d = d_row + d_x_step;
681 const int* s1 = s_row1 + sxs2;
682 const int* s2 = s_row2 + sxs2;
683 const int* s3 = s_row3 + sxs2;
684 for (
unsigned x=0;x<ni2;++x)
688 *d = int( 0.0625f * s1[-s_x_step] + 0.125f * s1[0] + 0.0625f * s1[s_x_step]
689 + 0.1250f * s2[-s_x_step] + 0.250f * s2[0] + 0.1250f * s2[s_x_step]
690 + 0.0625f * s3[-s_x_step] + 0.125f * s3[0] + 0.0625f * s3[s_x_step] +0.5);
710 const int* s0 = src_im;
711 unsigned ni=(src_ni+1)/2;
712 for (
unsigned i=0;i<ni;++i)
720 unsigned yhi = (src_nj-1)/2;
721 int* dest_last_row = dest_im + yhi*d_y_step;
722 const int* s_last = src_im + yhi*sys2;
723 for (
unsigned i=0;i<ni;++i)
725 dest_last_row[i]= *s_last;
735 unsigned src_ni,
unsigned src_nj,
736 std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step,
738 std::ptrdiff_t d_x_step, std::ptrdiff_t d_y_step)
740 std::ptrdiff_t sxs2 = s_x_step*2;
741 std::ptrdiff_t sys2 = s_y_step*2;
742 vxl_int_16* d_row = dest_im+d_y_step;
743 const vxl_int_16* s_row1 = src_im + s_y_step;
744 const vxl_int_16* s_row2 = s_row1 + s_y_step;
745 const vxl_int_16* s_row3 = s_row2 + s_y_step;
746 unsigned ni2 = (src_ni-2)/2;
747 unsigned nj2 = (src_nj-2)/2;
748 for (
unsigned y=0;y<nj2;++y)
752 vxl_int_16 * d = d_row + d_x_step;
753 const vxl_int_16* s1 = s_row1 + sxs2;
754 const vxl_int_16* s2 = s_row2 + sxs2;
755 const vxl_int_16* s3 = s_row3 + sxs2;
756 for (
unsigned x=0;x<ni2;++x)
760 *d = vxl_int_16( 0.0625f * s1[-s_x_step] + 0.125f * s1[0] + 0.0625f * s1[s_x_step]
761 + 0.1250f * s2[-s_x_step] + 0.250f * s2[0] + 0.1250f * s2[s_x_step]
762 + 0.0625f * s3[-s_x_step] + 0.125f * s3[0] + 0.0625f * s3[s_x_step] +0.5);
782 const vxl_int_16* s0 = src_im;
783 unsigned ni=(src_ni+1)/2;
784 for (
unsigned i=0;i<ni;++i)
792 unsigned yhi = (src_nj-1)/2;
793 vxl_int_16* dest_last_row = dest_im + yhi*d_y_step;
794 const vxl_int_16* s_last = src_im + yhi*sys2;
795 for (
unsigned i=0;i<ni;++i)
797 dest_last_row[i]= *s_last;
806 assert(scaleStep> 1.0 && scaleStep<=2.0);
810 double z = 1/std::sqrt(2.0*(scaleStep-1.0));
void vil_gauss_reduce_1plane(const vxl_byte *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, vxl_byte *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_2_3_1plane(const float *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, float *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.
Functions to smooth and sub-sample image in one direction.
vil_gauss_reduce_params(double scale_step)
void vil_gauss_reduce_121_1plane(const vxl_byte *src_im, unsigned src_ni, unsigned src_nj, std::ptrdiff_t s_x_step, std::ptrdiff_t s_y_step, vxl_byte *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.