00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _Matrix_Recursive_Filters_h_
00028 #define _Matrix_Recursive_Filters_h_
00029
00030 #include "barray2d.h"
00031
00034 namespace PLib {
00035
00036 struct Params{
00037 double a1,a2,a3,a4,a5,a6,a7,a8 ;
00038 double b1,b2 ;
00039 double c1,c2 ;
00040 double k ;
00041 };
00042
00043 void toParams(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double b1, double b2, double c1, double c2, double k, Params& params);
00044 void fromParams(const Params& params, double &a1, double &a2, double &a3, double &a4, double &a5, double &a6, double &a7, double &a8, double &b1, double &b2, double &c1, double &c2, double &k);
00045
00046 void generalRFx(const Params& params, const Basic2DArray<double> &x, Basic2DArray<double> &y);
00047 void generalRFy(const Params& params, const Basic2DArray<double> &r, Basic2DArray<double> &y);
00048 void generalRF(const Params& params, const Basic2DArray<double> &x, Basic2DArray<double> &y);
00049
00050 void smooth2ndOrder(Params& params, double alpha);
00051 void xderiv2ndOrderSmooth(Params& params, double alpha);
00052 void yderiv2ndOrderSmooth(Params& params, double alpha);
00053 void xderiv2ndOrder(Params& params, double alpha);
00054 void yderiv2ndOrder(Params& params, double alpha);
00055 void smooth1stOrder(Params& params, double alpha, double k0);
00056 void LL1stOrder(Params& params, double alpha);
00057
00058 void ubyteToDouble(const Basic2DArray<unsigned char>& img, Basic2DArray<double>& mat);
00059 void doubleToUbyte(const Basic2DArray<double>& mat, Basic2DArray<unsigned char>& img);
00060
00061 inline double firstDivDiff(double x0, double f0, double x1, double f1){
00062 return (f1-f0)/(x1-x0) ;
00063 }
00064
00065 inline double secondDivDiff(double x0, double f0, double x1, double f1, double x2, double f2){
00066 return (firstDivDiff(x1,f1,x2,f2)- firstDivDiff(x0,f0,x1,f1))/(x2-x0) ;
00067 }
00068
00069
00070 double quadInterp(double x, double x0, double f0, double x1, double f1, double x2, double f2);
00071
00072 int findEdge(const Basic2DArray<double>& dx, const Basic2DArray<double>& dy, Basic2DArray<double> &edge, Basic2DArray<double>& gradN, double thresh);
00073 int findSubEdge(const Basic2DArray<double>& dx, const Basic2DArray<double>& dy, Basic2DArray<double> &edge, double thresh, const Basic2DArray<double>& in);
00074
00075
00076 template <class T>
00077 class RecursiveFilter {
00078 public:
00079 RecursiveFilter(const Basic2DArray<T>& in, Basic2DArray<T>& out);
00080
00081 void compute_xderiv2ndOrderSmooth(double alpha);
00082 void compute_yderiv2ndOrderSmooth(double alpha);
00083 void compute_xderiv2ndOrder(double alpha);
00084 void compute_yderiv2ndOrder(double alpha);
00085 void compute_smooth1stOrder(double alpha, double k0);
00086 void compute_smooth1stOrder_x(double alpha, double k0);
00087 void compute_smooth1stOrder_y(double alpha, double k0);
00088 void compute_smooth2ndOrder(double alpha);
00089 void compute_smooth2ndOrder_x(double alpha);
00090 void compute_smooth2ndOrder_y(double alpha);
00091 void compute_LL1stOrder(double alpha);
00092 void compute_LL1stOrder_x(double alpha);
00093 void compute_LL1stOrder_y(double alpha);
00094
00095 protected:
00096 Params params ;
00097 const Basic2DArray<T> &input ;
00098 Basic2DArray<T>& output ;
00099 Basic2DArray<double> *input_, *output_ ;
00100 };
00101
00102
00103 template <class T>
00104 inline void toDouble(const Basic2DArray<T>& a, Basic2DArray<double>& b){
00105 b.resize(a.rows(),a.cols());
00106 for(int i=a.rows()-1;i>=0;--i)
00107 for(int j=a.cols()-1;j>=0;--j)
00108 b(i,j) = double(a(i,j)) ;
00109 }
00110
00111 template <class T>
00112 inline void fromDouble(const Basic2DArray<double>& a, Basic2DArray<T>& b){
00113 b.resize(a.rows(),a.cols());
00114 for(int i=a.rows()-1;i>=0;--i)
00115 for(int j=a.cols()-1;j>=0;--j)
00116 b(i,j) = T(a(i,j)) ;
00117 }
00118
00119 template <>
00120 inline void toDouble(const Basic2DArray<double>& a, Basic2DArray<double>& b){
00121 if(&a == &b)
00122 return ;
00123 b.resize(a.rows(),a.cols());
00124 for(int i=a.rows()-1;i>=0;--i)
00125 for(int j=a.cols()-1;j>=0;--j)
00126 b(i,j) = double(a(i,j)) ;
00127 }
00128
00129 template <>
00130 inline void fromDouble(const Basic2DArray<double>& a, Basic2DArray<double>& b){
00131 if(&a == &b)
00132 return ;
00133 b.resize(a.rows(),a.cols());
00134 for(int i=a.rows()-1;i>=0;--i)
00135 for(int j=a.cols()-1;j>=0;--j)
00136 b(i,j) = double(a(i,j)) ;
00137 }
00138
00139
00140 }
00141
00142 #endif
00143