core/vil1/vil1_convolve_1d_y.txx

Go to the documentation of this file.
00001 // This is core/vil1/vil1_convolve_1d_y.txx
00002 #ifndef vil1_convolve_1d_y_txx_
00003 #define vil1_convolve_1d_y_txx_
00004 
00005 #ifndef fsm_dont_croak // this file should only be #included from vil1_convolve_1d.txx
00006 croak
00007 #endif
00008 
00009 #include "vil1_convolve.h"
00010 #include <vcl_cstdlib.h> // for vcl_abort()
00011 
00012 template <class I1, class I2, class AC, class O>
00013 void vil1_convolve_1d_y(vil1_convolve_signal_1d<I1 const> const &kernel,
00014                         vil1_convolve_signal_2d<I2 const> const &input,
00015                         AC *,
00016                         vil1_convolve_signal_2d<O> const &output,
00017                         vil1_convolve_boundary_option b,
00018                         vil1_convolve_boundary_option e)
00019 {
00020   // compute ranges of i, x, y here.
00021   int i0 = kernel.begin_-kernel.origin_;
00022   int i1 = kernel.end_  -kernel.origin_;
00023 
00024   int x0 = output.beginx_-output.originx_;
00025   int x1 = output.endx_  -output.originx_;
00026 
00027   int y0 = output.beginy_-output.originy_;
00028   int y1 = output.endy_  -output.originy_;
00029 
00030   // compute total weight of the kernel.
00031   // FIXME assumes non-negative kernel.
00032   AC total_weight = 0;
00033   for (int i=i0; i<i1; ++i)
00034     total_weight += AC(value1d(kernel, i));
00035 
00036 
00037   // this is not very efficient at the moment, but my main
00038   // concern for now is that it works correctly.
00039   for (int y=y0; y<y1; ++y) {
00040     for (int x=x0; x<x1; ++x) {
00041       AC ac = 0; // accumulated "kernel * input" terms.
00042       AC wt = 0; // accumulated "kernel" terms.
00043       bool zero = false;
00044 
00045       for (int i=i0; i<i1 && !zero; ++i) {
00046         // value of kernel at i :
00047         AC kval = AC(value1d(kernel, i));
00048 
00049         int yy = y-i;
00050         if (yy < y0) switch (b) {
00051         case vil1_convolve_no_extend:
00052           zero = true; /*FIXME*/
00053           break;
00054         case vil1_convolve_zero_extend:
00055           wt += kval;
00056           break;
00057         case vil1_convolve_constant_extend:
00058           ac += kval * AC(value2d(input, x, y0));
00059           wt += kval;
00060           break;
00061         case vil1_convolve_periodic_extend:
00062           ac += kval * AC(value2d(input, x, yy+(y1-y0)));
00063           wt += kval;
00064           break;
00065         case vil1_convolve_reflect_extend:
00066           ac += kval * AC(value2d(input, x, 2*y0-yy));
00067           wt += kval;
00068           break;
00069         case vil1_convolve_trim:
00070           break;
00071         default:
00072           vcl_abort();
00073           break;
00074         }
00075 
00076         else if (yy >= y1) switch (e) {
00077         case vil1_convolve_no_extend:
00078           zero = true; /*FIXME*/
00079           break;
00080         case vil1_convolve_zero_extend:
00081           wt += kval;
00082           break;
00083         case vil1_convolve_constant_extend:
00084           ac += kval * AC(value2d(input, x, y1-1));
00085           wt += kval;
00086           break;
00087         case vil1_convolve_periodic_extend:
00088           ac += kval * AC(value2d(input, x, yy-(y1-y0)));
00089           wt += kval;
00090           break;
00091         case vil1_convolve_reflect_extend:
00092           ac += kval * AC(value2d(input, x, 2*(y1-1)-yy));
00093           wt += kval;
00094           break;
00095         case vil1_convolve_trim:
00096           break;
00097         default:
00098           vcl_abort();
00099           break;
00100         }
00101 
00102         else {
00103           ac += kval * AC(value2d(input, x, yy));
00104           wt += kval;
00105         }
00106       }
00107 
00108       // compute and store final value.
00109       if (zero)
00110         value2d(output, x, y) = AC(0);
00111       else if (wt)
00112         value2d(output, x, y) = O(ac * total_weight / wt);
00113     }
00114   }
00115 }
00116 
00117 #endif // vil1_convolve_1d_y_txx_

Generated on Tue Oct 7 05:08:18 2008 for core/vil1 by  doxygen 1.5.1