contrib/tbl/vipl/vipl_gaussian_convolution.h
Go to the documentation of this file.
00001 #ifndef vipl_gaussian_convolution_h_
00002 #define vipl_gaussian_convolution_h_
00003 //:
00004 // \file
00005 // \brief gaussian smoothing
00006 //
00007 //   This image processing class is implemented using the vipl filters,
00008 //   which means that it can be used with any image class (IUE or not,
00009 //   TargetJr or not, vil or vil1 or not) of any pixel data type.
00010 //
00011 //   Note that DataIn values must allow addition and multiplication with floats;
00012 //   and that the result be expressible as DataOut, possibly after rounding.
00013 //   Probably only float and double make sense as DataOut (?)
00014 //
00015 //   As this is a separable filter, it is implemented as a row-based 1-D filter
00016 //   followed by a column-based 1-D step.
00017 //
00018 // \author Peter Vanroose, K.U.Leuven (ESAT/PSI)
00019 // \date   14 March 1999.
00020 //
00021 // \verbatim
00022 // Modifications:
00023 //   Peter Vanroose, Aug.2000 - adapted to vxl
00024 // \endverbatim
00025 //
00026 
00027 #include <vipl/filter/vipl_filter_2d.h> // parent class
00028 
00029 //: Gaussian smoothing
00030 //
00031 //   Gaussian filtering is an operation that replaces a pixel with the
00032 //   average value of its surrounding pixels, in a certain neighbourhood,
00033 //   according to a Gaussian distribution (with given sigma= std deviation).
00034 //   (The window is cut when `cutoff' (default: 0.01) of the probability mass
00035 //   lies out of the window.)
00036 template <class ImgIn,class ImgOut,class DataIn,class DataOut, VCL_DFL_TYPE_PARAM_STLDECL(PixelItr, vipl_trivial_pixeliter) >
00037 class vipl_gaussian_convolution : public vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>
00038 {
00039   // -+-+- data members: -+-+-
00040  private:
00041   double sigma_;
00042   double& ref_sigma(){return sigma_;}
00043   void put_sigma(double v){sigma_=v;}
00044   double cutoff_;
00045   double& ref_cutoff(){return cutoff_;}
00046   void put_cutoff(double v){cutoff_=v;}
00047  public:
00048   double sigma() const {return sigma_;}
00049   double cutoff() const {return cutoff_;}
00050 
00051  private:
00052   // attribute to store the "temporary mask"
00053   double* mask_;
00054   inline double*& ref_mask(){return mask_;}
00055   inline void put_mask(double* v){mask_=v;}
00056   inline double* mask() const{return mask_;}
00057   int masksize_;
00058   inline int& ref_masksize(){return masksize_;}
00059   inline void put_masksize(int v){masksize_=v;}
00060   inline int masksize() const{return masksize_;}
00061 
00062 // -+-+- constructors/destructors: -+-+-
00063  public:
00064   inline vipl_gaussian_convolution(double s=1, double c=0.01)
00065            : vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>()
00066            , sigma_(s)
00067            , cutoff_(c)
00068            , mask_(0)
00069            , masksize_(0)
00070     { if (s < 0) ref_sigma() = -s;
00071       if (c < 0.005) ref_cutoff() = 0.005;
00072       if (c > 0.5) ref_cutoff() = 0.5; }
00073 
00074   inline vipl_gaussian_convolution(vipl_gaussian_convolution const& A)
00075            : vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>(A)
00076            , sigma_(A.sigma())
00077            , cutoff_(A.cutoff())
00078            , mask_(0)
00079            , masksize_(0) {}
00080 
00081   inline ~vipl_gaussian_convolution() {}
00082 
00083 // -+-+- required method for filters: -+-+-
00084   bool section_applyop();
00085 // -+-+- optional method for filters, compute mask only once in preop, free in postop: -+-+-
00086   bool preop();
00087   bool postop();
00088 };
00089 
00090 #ifdef INSTANTIATE_TEMPLATES
00091 #include "vipl_gaussian_convolution.txx"
00092 #endif
00093 
00094 #endif // vipl_gaussian_convolution_h_