Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Segmentation/XVColorSeg.h

00001 // *** BEGIN_XVISION2_COPYRIGHT_NOTICE ***
00002 // *** END_XVISION2_COPYRIGHT_NOTICE ***
00003 
00004 #ifndef _XVCOLORSEG_H_
00005 #define _XVCOLORSEG_H_
00006 
00007 #include <math.h>
00008 #include <XVSegmentation.h>
00009 #include <XVTools.h>
00010 #include <XVImageRGB.h>
00011 #include <XVImageScalar.h>
00012 
00013 #define NULL_HUE 5555
00014 #define DEFAULT_DISTANCE  20
00015 #define DEFAULT_SECTOR_NUM 360
00016 #define DEFAULT_HUERANGE_WIDTH 4
00017 
00018 typedef struct{
00019 
00020   float min;
00021   float max;
00022 
00023 } HUERANGE;
00024 
00025 static const HUERANGE DEFAULT_HUERANGE = {-1, -1};
00026 
00027 /************************************************
00028  * Table and Segmentation classes for Hue based
00029  * Segmentation
00030  ************************************************/
00031 
00037 /************************************************
00038  * Table and Segmentation classes for Sector
00039  * based Segmentation.  The hue values of the
00040  * pixels are divided into sectors
00041  * and an image is segmented based on those 
00042  * sectors
00043  ************************************************/
00044 
00049 template <class T, class Y>
00050 class HueSectorTable : public virtual RGBTable<T, Y>{
00051 
00052  protected:
00053 
00054   u_char darkPix, brightPix;
00055 
00056   int numOfSectors;
00057 
00058   Y computePixelValue(T);
00059   
00060  public:
00061   
00062   HueSectorTable(int num, u_char dp, u_char bp) : RGBTable<T, Y>(), numOfSectors(num), darkPix(dp), brightPix(bp) { 
00063     this->buildTable(); 
00064   };
00065 
00066   int getSectors(){ return numOfSectors; };
00067 };
00068 
00073 template <class T, class Y>
00074 class XVHueSeg : public virtual XVSegmentation<T, Y>{
00075 
00076  protected:
00077 
00078   int numOfSectors;
00079 
00080  public:
00081 
00082   XVHueSeg(int sec = DEFAULT_SECTOR_NUM, 
00083         u_char dp = DEFAULT_DARK_PIXEL, 
00084         u_char bp = DEFAULT_BRIGHT_PIXEL);
00085   XVHueSeg(HueSectorTable<T, Y> *);
00086 
00087   float findBestHue(const XVImageRGB<T> &);
00088 
00089   int getNumOfSectors(){ return this->numOfSectors; }
00090 
00091   void update(const XVImageBase<T> & roiIM){};
00092 };
00093 
00094 /************************************************
00095  * Table and Segmentation classes for Color
00096  * Segmentation based on the distance from some
00097  * specified color.  
00098  ************************************************/
00099 
00108 template <class T>
00109 class RGBDistanceTable : public virtual RGBTable<T, bool>{
00110 
00111  protected:
00112 
00113   T baseColor;
00114   float bcLength;
00115   u_short distance;
00116 
00117   bool computePixelValue(T);
00118   
00119  public:
00120 
00121   RGBDistanceTable(T, u_short);
00122 };
00123 
00124 inline bool RGB_DISTANCE_CHECK(const bool val){ return val; };
00125 
00131 template <class T>
00132 class XVRGBDistanceSeg : public virtual XVSegmentation<T, bool>{
00133 
00134  public:
00135 
00136   XVRGBDistanceSeg(T, u_short dist = DEFAULT_DISTANCE,
00137              RGBDistanceTable<T> * table = NULL);
00138 
00139   void update(const XVImageBase<T> & roiIM){};
00140 
00141 };
00142 
00143 
00144 /************************************************
00145  * Table and Segmentation classes for Color
00146  * Segmentation based on a range of Hue values
00147  ************************************************/
00148 
00156 template <class T, class Y>
00157 class HueRangeTable : public virtual RGBTable<T, Y>{
00158 
00159  protected:
00160 
00161   Y computePixelValue(T);
00162   u_char darkPix, brightPix;
00163 
00164  public:
00165 
00166   HUERANGE hueRange;
00167 
00168   HueSectorTable<T, Y> * hueTable;
00169   
00170   HueRangeTable(HUERANGE range, u_char dp, u_char bp) : RGBTable<T, Y>() { 
00171     hueTable = new HueSectorTable<T, Y>(DEFAULT_SECTOR_NUM, dp, bp);
00172     hueRange = range; 
00173     this->buildTable(); 
00174   }
00175 
00176   ~HueRangeTable(){ delete hueTable; };
00177 
00178   void updateTable(HUERANGE);
00179   HUERANGE getRange() { return hueRange; }
00180 };
00181 
00182 template <class Y>
00183 inline bool RANGE_SEGFUNC(const Y val){ return (bool)val; }
00184 
00185 template <class T, class Y>
00186 class XVHueRangeSeg : public virtual XVSegmentation<T, Y>{
00187 
00188   int rangeWidth;
00189 
00190  public:
00191 
00192   XVHueRangeSeg(HUERANGE range = DEFAULT_HUERANGE, int rW = DEFAULT_HUERANGE_WIDTH,
00193           int sec = DEFAULT_SECTOR_NUM, 
00194           u_char dp = DEFAULT_DARK_PIXEL, u_char bp = DEFAULT_BRIGHT_PIXEL);
00195   XVHueRangeSeg(HueRangeTable<T, Y> *);
00196   XVHueRangeSeg(XVImageRGB<T> &, int rW = DEFAULT_HUERANGE_WIDTH,
00197           int sec = DEFAULT_SECTOR_NUM,
00198           u_char dp = DEFAULT_DARK_PIXEL, u_char bp = DEFAULT_BRIGHT_PIXEL);
00199  
00200   void updateTable(HUERANGE);
00201 
00202   float findBestHue(const XVImageRGB<T> &);
00203 
00204   void update(const XVImageBase<T> &);
00205   HUERANGE getRange(){ return dynamic_cast<HueRangeTable<T, Y> *>(lookup)->getRange(); }
00206 };
00207 
00208 #endif
00209 

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000