Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Representations/Perception/ColorTable32K.h

Go to the documentation of this file.
00001 /** 
00002 * @file ColorTable32K.h
00003 * Declaration of class ColorTable32K.
00004 *
00005 * @author <A href=mailto:walter.nistico@uni-dortmund.de>Walter Nistico</A>
00006 */
00007 
00008 #ifndef _ColorTable32K_h_
00009 #define _ColorTable32K_h_
00010 
00011 #include "ColorTable.h"
00012 #include "Tools/Streams/InOut.h"
00013 #include "Tools/Math/Vector3.h"
00014 #include "ColorClassImage.h"
00015 #include "Image.h"
00016 
00017 /**
00018 * @class ColorTable32K
00019 *
00020 * Contains a ColorTable32K which can decode the color for
00021 * every 16 * 4 * 4 cube in the 255 * 255 * 255 YUV color space.
00022 * The 64K elements color cube is packed into a 32KBytes color table (each element is just 4bits)
00023 * accessed through fast shift and masking operations
00024 *
00025 * @author <A href=mailto:walter.nistico@uni-dortmund.de>Walter Nistico</A>
00026 */
00027 class ColorTable32K : public ColorTable
00028 {
00029 public:
00030   /** Constructor */
00031   ColorTable32K();
00032 
00033   /** Destructor */
00034   ~ColorTable32K();
00035 
00036   /** 
00037   * Calculates the color class of a pixel, it's fast because is non-virtual and inline,
00038   * obviously can't be used through the common ColorTable interface
00039   * @param y the y value of the pixel
00040   * @param u the u value of the pixel
00041   * @param v the v value of the pixel
00042   * @return the color class
00043   */
00044   inline colorClass getColorClassFast(const unsigned char y, 
00045     const unsigned char u, 
00046     const unsigned char v) const
00047   {
00048     unsigned char subY = (y&0x10)>>2;
00049     unsigned char internal_y = y>>5;
00050     unsigned char internal_u = u>>2;
00051     unsigned char internal_v = v>>2;
00052     int colorMapPos = (internal_y<<12)|(internal_v<<6)|internal_u;
00053     return (colorClass) (((colorClasses[colorMapPos])>>subY)&0x0f);
00054   }
00055 
00056 
00057   /** 
00058   * Calculates the color class of a pixel.
00059   * @param y the y value of the pixel
00060   * @param u the u value of the pixel
00061   * @param v the v value of the pixel
00062   * @return the color class
00063   */
00064   virtual colorClass getColorClass (const unsigned char y, 
00065     const unsigned char u, 
00066     const unsigned char v) const;
00067 
00068   /**
00069   * Computes an axis aligned box around all positions of a specified color
00070   * in YUV space
00071   * @param color The color
00072   * @param pNear The corner of the box nearest to the origin
00073   * @param pFar The corner of the box farthest to the origin
00074   */
00075   void getBoxAroundColorClass(colorClass color, 
00076                               Vector3<int>& pNear, Vector3<int>& pFar);
00077 
00078   /**
00079   * Segments an image to a color class image.
00080   * 
00081   * This doesn't need to be used in the image processor, but is needed for visualisation
00082   * of color tables.
00083   * @param image A reference to the image to be segmented
00084   * @param colorClassImage A reference to the color class image to be created
00085   */
00086   virtual void generateColorClassImage(const Image& image, 
00087     ColorClassImage& colorClassImage) const;
00088 
00089   /**
00090   * Generates an image that contains all pixels that have the specified color class.
00091   * 
00092   * @param image A reference to the image to be segmented
00093   * @param colorClassImage A reference to the color class image to be created
00094   * @param colorClass The color class. 
00095   */
00096   virtual void generateColorClassImage(const Image& image, 
00097     ColorClassImage& colorClassImage,
00098     colorClass colorClass
00099     ) const;
00100 
00101   /**
00102   * Segments an image to an color class image.
00103   * 
00104   * This doesn't need to used in the image processor, but is needed for visualisation
00105   * of color tables.
00106   * @param image A reference to the image to be segmented
00107   * @param colorClassImage A reference to the color class image to be created
00108   */
00109   virtual void generateHighResColorClassImage(const Image& image, 
00110     ColorClassImage& colorClassImage) const;
00111 
00112   /**
00113   * Generates an image that contains all pixels that have the specified color class.
00114   * 
00115   * @param image A reference to the image to be segmented
00116   * @param colorClassImage A reference to the color class image to be created
00117   * @param colorClass The color class. 
00118   */
00119   virtual void generateHighResColorClassImage(const Image& image, 
00120     ColorClassImage& colorClassImage,
00121     colorClass colorClass
00122     ) const;
00123 
00124   /**
00125   * Unpacks the color table into a 64K array, used for performance testing 
00126   * (higher cache hit rate Vs less instructions per pixel)
00127   * 
00128   * @param unpackedCube Pointer to the unpacked buffer
00129   * @param packedCube Pointer to the packed buffer
00130   */
00131   void unpack(unsigned char* unpackedCube, const unsigned char* packedCube);
00132 
00133   /** 
00134   * The color table (array of 32K elements).
00135   * Each element in the array contains 2 points in the color space having same U,V and adjacent Y.
00136   * Quantization is 16x4x4 (YUV)
00137   */
00138   unsigned char colorClasses[8*64*64];
00139 
00140   /** 
00141   * The unpacked color table (array of 64K elements), used for performance testing
00142   */
00143   unsigned char colorClassesUnpacked[16*64*64];
00144   
00145   //!@name Members to be used by the ColorTable32K dialog
00146   //!@{
00147 
00148   /** Resets the color table to noColor */
00149   void clear();
00150   
00151   /** Sets all cubes that have the given color class to noColor */
00152   void clearChannel(colorClass colorClass);
00153   
00154   /** 
00155   * Sets the color class for a pixel in the color space given by y, u, v
00156   * to the given color class.
00157   */
00158   void addColorClass(
00159     colorClass colorClass,
00160     unsigned char y,
00161     unsigned char u,
00162     unsigned char v
00163     );
00164 
00165   /** 
00166   * Sets the color class for a cube with the size "range" around a pixel
00167   * given by y,u,v to the given color class.
00168   */
00169   void addColorClass(
00170     colorClass colorClass,
00171     unsigned char y, 
00172     unsigned char u, 
00173     unsigned char v, 
00174     unsigned char range
00175     );
00176 
00177   /**
00178   * Sets the color class for all sub cubes within the specified cuboid to the given color class.
00179   */
00180   void addCuboidToColorClass(
00181     colorClass colorClass,
00182     unsigned char yMin, 
00183     unsigned char uMin, 
00184     unsigned char vMin, 
00185     unsigned char yMax, 
00186     unsigned char uMax, 
00187     unsigned char vMax
00188     );
00189   
00190   /**
00191   * Sets the color class for a cube with the size "range" around a pixel
00192   * given by y,u,v to noColor.
00193   */
00194   void removeColorClass(
00195     unsigned char y, 
00196     unsigned char u, 
00197     unsigned char v, 
00198     unsigned char range
00199     );
00200 
00201 };
00202 
00203 /**
00204  * Streaming operator that reads a ColorTable32K from a stream.
00205  * @param stream The stream from which is read.
00206  * @param colorTable32K The ColorTable32K object.
00207  * @return The stream.
00208  */ 
00209 In& operator>>(In& stream,ColorTable32K& colorTable32K);
00210  
00211 /**
00212  * Streaming operator that writes a ColorTable32K to a stream.
00213  * @param stream The stream to write on.
00214  * @param colorTable32K The ColorTable32K object.
00215  * @return The stream.
00216  */ 
00217 Out& operator<<(Out& stream, const ColorTable32K& colorTable32K);
00218 
00219 #endif   //  _ColorTable32K_h_

Generated on Mon Mar 20 22:00:02 2006 for GT2005 by doxygen 1.3.6