Main Page   Class Hierarchy   Compound List   File List   Compound Members  

rec_filter.h

00001 /*=============================================================================
00002         File: rec_filter.h
00003      Purpose:       
00004     Revision: $Id: rec_filter.h,v 1.2 2002/05/13 21:07:45 philosophil Exp $
00005   Created by: Philippe Lavoie          (18 February 1999)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1998 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 

Generated on Tue Jun 24 13:26:58 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002