contrib/tbl/vipl/vipl_threshold.h
Go to the documentation of this file.
00001 #ifndef vipl_threshold_h_
00002 #define vipl_threshold_h_
00003 //:
00004 // \file
00005 // \brief set pixel to given value if above/below certain threshold
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 //   This class actually implements two threshold operations, namely the
00012 //   `classical' single threshold mapping where pixel values not larger than
00013 //   T are mapped to L, values larger than T to H; and the `clipping'
00014 //   operation where only pixel values below T are mapped to L, the others
00015 //   left unchanged.
00016 //
00017 //   For the first version, the constructor must be given three parameters:
00018 //   T, L and H.  For the second version, two parameters: T and L.
00019 //   In the second situation, there clearly must be an implicit conversion
00020 //   from DataIn to DataOut.  Note that this is not necessary in the
00021 //   first situation, because all output pixels will be either L or H.
00022 //
00023 //   Note that the input image data type must support "operator<=()"; thus
00024 //   thresholding of colour images makes no sense (unless you define a
00025 //   sensible "<=" for RGB triples).
00026 //
00027 // \author Peter Vanroose, K.U.Leuven (ESAT/PSI)
00028 // \date   15 November 1997.
00029 //
00030 // \verbatim
00031 // Modifications:
00032 //   Terry Boult - Dec. 1997 - made various mods for newgen and IUE consistency
00033 //   Peter Vanroose, Aug.2000 - adapted to vxl
00034 // \endverbatim
00035 //
00036 // \example examples/example1_threshold.cxx
00037 // \example examples/example2_threshold.cxx
00038 // \example examples/example3_threshold.cxx
00039 // \example examples/example4_threshold.cxx
00040 
00041 #include <vipl/filter/vipl_filter_2d.h> // parent class
00042 
00043 //: set pixel to given value if above/below certain threshold
00044 template <class ImgIn,class ImgOut,class DataIn,class DataOut, VCL_DFL_TYPE_PARAM_STLDECL(PixelItr, vipl_trivial_pixeliter) >
00045 class vipl_threshold : public vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>
00046 {
00047   // -+-+- data members: -+-+-
00048  private: DataIn threshold_;
00049  public: DataIn threshold() const { return threshold_; }
00050  private: DataOut below_;
00051  public: DataOut below() const { return below_; }
00052  private: DataOut above_;
00053  public: DataOut above() const { return above_; }
00054  private: bool aboveset_;
00055  public: bool aboveset() const { return aboveset_; }
00056 
00057   // -+-+- constructors/destructors: -+-+-
00058  public:
00059   inline vipl_threshold(DataIn t=128, DataOut b=1)
00060     : vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>(), threshold_(t), below_(b), above_(0), aboveset_(false) {}
00061   inline vipl_threshold(DataIn t, DataOut b, DataOut a)
00062     : vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>(), threshold_(t), below_(b), above_(a), aboveset_(true) {}
00063   inline vipl_threshold(vipl_threshold const& A)
00064     : vipl_filter_2d<ImgIn,ImgOut,DataIn,DataOut,PixelItr>(A), threshold_(A.threshold()), below_(A.below()),
00065       above_(A.above()), aboveset_(A.aboveset()) {}
00066   inline ~vipl_threshold() {}
00067 
00068   // -+-+- required method for filters: -+-+-
00069   bool section_applyop();
00070 };
00071 
00072 #ifdef INSTANTIATE_TEMPLATES
00073 #include "vipl_threshold.txx"
00074 #endif
00075 
00076 #endif // vipl_threshold_h_