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

# Representations/Perception/ColorTable64.h

Go to the documentation of this file.

    00001 /**
    00002 * @file ColorTable64.h
    00003 * Declaration of class ColorTable64.
    00004 *
    00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00006 * @author <A href=mailto:martin@martin-loetzsch.de>Martin Lötzsch</A>
    00007 */
    00008
    00009 #ifndef _ColorTable64_h_
    00010 #define _ColorTable64_h_
    00011
    00012 // forward declaration
    00013 class ColorTable64;
    00014
    00015 #include "ColorTable.h"
    00016 #include "Tools/Streams/InOut.h"
    00017 #include "Tools/Math/Vector3.h"
    00018 #include "ColorClassImage.h"
    00019 #include "Image.h"
    00020
    00021 /**
    00022 * @class ColorTable64
    00023 *
    00024 * Contains a ColorTable64 which can decode the color for
    00025 * every 4 * 4 * 4 cube in the 255 * 255 * 255 YUV color space.
    00026 *
    00027 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00028 * @author <A href=mailto:martin@martin-loetzsch.de>Martin Lötzsch</A>
    00029 */
    00030 class ColorTable64 : public ColorTable
    00031 {
    00032 public:
    00033   /** Constructor */
    00034   ColorTable64();
    00035
    00036   /** Destructor */
    00037   ~ColorTable64();
    00038
    00039   enum Format {CT32K, CT64};
    00040
    00041   /**
    00042   * Calculates the color class of a pixel.
    00043   * @param y the y value of the pixel
    00044   * @param u the u value of the pixel
    00045   * @param v the v value of the pixel
    00046   * @return the color class
    00047   */
    00048   virtual colorClass getColorClass (const unsigned char y,
    00049     const unsigned char u,
    00050     const unsigned char v) const
    00051   {
    00052     return (colorClass) colorClasses[y/4][u/4][v/4];
    00053   }
    00054
    00055   /**
    00056   * Computes an axis aligned box around all positions of a specified color
    00057   * in YUV space
    00058   * @param color The color
    00059   * @param pNear The corner of the box nearest to the origin
    00060   * @param pFar The corner of the box farthest to the origin
    00061   */
    00062   void getBoxAroundColorClass(colorClass color,
    00063                               Vector3<int>& pNear, Vector3<int>& pFar);
    00064   /**
    00065   * Segments an image to an color class image.
    00066   *
    00067   * This doesn't need to used in the image processor, but is needed for visualisation
    00068   * of color tables.
    00069   * @param image A reference to the image to be segmented
    00070   * @param colorClassImage A reference to the color class image to be created
    00071   */
    00072   virtual void generateColorClassImage(const Image& image,
    00073     ColorClassImage& colorClassImage) const;
    00074
    00075   /**
    00076   * Generates an image that contains all pixels that have the specified color class.
    00077   *
    00078   * @param image A reference to the image to be segmented
    00079   * @param colorClassImage A reference to the color class image to be created
    00080   * @param colorClass The color class.
    00081   */
    00082   virtual void generateColorClassImage(const Image& image,
    00083     ColorClassImage& colorClassImage,
    00084     colorClass colorClass
    00085     ) const;
    00086
    00087   /**
    00088   * Segments an image to an color class image.
    00089   *
    00090   * This doesn't need to used in the image processor, but is needed for visualisation
    00091   * of color tables.
    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   */
    00095   virtual void generateHighResColorClassImage(const Image& image,
    00096     ColorClassImage& colorClassImage) const;
    00097
    00098   /**
    00099   * Generates an image that contains all pixels that have the specified color class.
    00100   *
    00101   * @param image A reference to the image to be segmented
    00102   * @param colorClassImage A reference to the color class image to be created
    00103   * @param colorClass The color class.
    00104   */
    00105   virtual void generateHighResColorClassImage(const Image& image,
    00106     ColorClassImage& colorClassImage,
    00107     colorClass colorClass
    00108     ) const;
    00109
    00110   /**
    00111   * The color table.
    00112   * Each element in the array contains the color class of a 4x4x4 cube in the color space.
    00113   */
    00114   unsigned char colorClasses[64][64][64];
    00115
    00116   //!@name Members to be used by the ColorTable64 dialog
    00117   //!@{
    00118
    00119   /** Sets the color class of every 4x4x4 to noColor */
    00120   void clear();
    00121
    00122   /** Sets all cubes that have the given color class to noColor */
    00123   void clearChannel(colorClass colorClass);
    00124
    00125   /**
    00126   * Sets the color class for a pixel in the color space given by y, u, v
    00127   * to the given color class.
    00128   */
    00129   void addColorClass(
    00130     colorClass colorClass,
    00131     unsigned char y,
    00132     unsigned char u,
    00133     unsigned char v
    00134     );
    00135
    00136   /**
    00137   * Sets the color class for a cube with the size "range" around a pixel
    00138   * given by y,u,v to the given color class.
    00139   */
    00140   void addColorClass(
    00141     colorClass colorClass,
    00142     unsigned char y,
    00143     unsigned char u,
    00144     unsigned char v,
    00145     unsigned char range
    00146     );
    00147
    00148   /**
    00149   * Sets the color class for all sub cubes within the specified cuboid to the given color class.
    00150   */
    00151   void addCuboidToColorClass(
    00152     colorClass colorClass,
    00153     unsigned char yMin,
    00154     unsigned char uMin,
    00155     unsigned char vMin,
    00156     unsigned char yMax,
    00157     unsigned char uMax,
    00158     unsigned char vMax
    00159     );
    00160
    00161   /**
    00162   * Sets the color class for a cube with the size "range" around a pixel
    00163   * given by y,u,v to noColor.
    00164   */
    00165   void removeColorClass(
    00166     unsigned char y,
    00167     unsigned char u,
    00168     unsigned char v,
    00169     unsigned char range
    00170     );
    00171
    00172   void setFormat(Format form)
    00173   {
    00174     format = form;
    00175   }
    00176
    00177   enum {CT32K_SIZE = 8*64*64, CT64_SIZE = 64*64*64};
    00178
    00179   /**
    00180    * Streaming operator that reads a ColorTable64 from a stream.
    00181    * @param stream The stream from which is read.
    00182    * @param colorTable64 The ColorTable64 object.
    00183    * @return The stream.
    00184    */
    00185   friend In& operator>>(In& stream,ColorTable64& colorTable64);
    00186   //!@}
    00187
    00188   /**
    00189   * This function marks the outer pixels of all segmented colors in the colorspace as noColor.
    00190   */
    00191   void shrink();
    00192
    00193   /**
    00194   * This function marks the outer pixels of the parameter color in the colorspace as noColor.
    00195   * &param color The color to shrink
    00196   */
    00197   void shrink(unsigned char color);
    00198
    00199   /**
    00200   * This function marks all noColor pixels in the colorspace, which are neighbors of segmented
    00201   * pixels, with the neighboring color.
    00202   */
    00203   void grow();
    00204
    00205   /**
    00206   * This function marks all noColor pixels in the colorspace, which are neighbors of the parameter color,
    00207   * with the neighboring color.
    00208   */
    00209   void grow(unsigned char color);
    00210
    00211 private:
    00212
    00213   Format format;
    00214
    00215   static void convert32Kto64(const unsigned char* c32k, unsigned char c64[64][64][64]);
    00216
    00217   /**
    00218   * Returns true if the pixel y,u,v in the  colorClassesArray has more than x or x neighbors.
    00219   * @param y the y coordinate of the pixel in the colorspace
    00220   * @param u the u coordinate of the pixel in the colorspace
    00221   * @param v the v coordinate of the pixel in the colorspace
    00222   * @param x the number of desired pixels
    00223   * @param colorClassesArray the Array with the colorClasses
    00224   */
    00225   bool hasXNeighbors(unsigned char y, unsigned char u, unsigned char v, int x, unsigned char colorClassesArray[64][64][64]);
    00226
    00227   /**
    00228   * Returns the color of one of the neighboring pixels of the pixel y,u,v.
    00229   * If no direct neighbor is present, noColor s returned.
    00230   * @param y the y coordinate of the pixel in the colorspace
    00231   * @param u the u coordinate of the pixel in the colorspace
    00232   * @param v the v coordinate of the pixel in the colorspace
    00233   * @param colorClassesArray the Array with the colorClasses
    00234   */
    00235   unsigned char getNeighborColor(unsigned char y, unsigned char u, unsigned char v, unsigned char colorClassesArray[64][64][64]);
    00236
    00237 };
    00238
    00239 /**
    00240  * Streaming operator that writes a ColorTable64 to a stream.
    00241  * @param stream The stream to write on.
    00242  * @param colorTable64 The ColorTable64 object.
    00243  * @return The stream.
    00244  */
    00245 Out& operator<<(Out& stream, const ColorTable64& colorTable64);
    00246
    00247 #endif   //  _ColorTable64_h_