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

Representations/Perception/Image.h

Go to the documentation of this file.
00001 /**
00002  * @file Image.h
00003  * 
00004  * Declaration of class Image
00005  */ 
00006 
00007 #ifndef __Image_h_
00008 #define __Image_h_
00009 
00010 #include "CameraInfo.h"
00011 
00012 // forward declaration
00013 class Image;
00014 
00015 #include "Tools/Streams/InOut.h"
00016 #include "Representations/Perception/ColorTable.h"
00017 #include "Tools/ColorClasses.h"
00018 #include "Tools/Math/Common.h"
00019 #include <string.h>
00020 
00021 /**
00022 * Platform independend definition of an image class
00023 */
00024 class Image
00025 {
00026 public:
00027   /** constructs an image */
00028   Image();
00029 
00030   /** deconstructs an image */
00031   ~Image();
00032 
00033   bool          hasColorTable(void);
00034   void          setColorTable(const ColorTable* ct);
00035   char          getClassifiedColor(int x, int y);
00036   char          getClassifiedColor(unsigned long index);
00037   
00038 
00039   /** Converts an YUV image into an RGB image.
00040    *  @param yuvImage The given YUV image
00041    */
00042   void convertFromYUVToRGB(const Image& yuvImage);
00043 
00044   /** Converts an YCbCr pixel into an RGB pixel.
00045    *  @param Y The Y channel of the source pixel.
00046    *  @param Cb The Cb channel of the source pixel.
00047    *  @param Cr The Cr channel of the source pixel.
00048    *  @param R The R channel of the target pixel.
00049    *  @param G The G channel of the target pixel.
00050    *  @param B The B channel of the target pixel.
00051    */
00052   static void convertFromYCbCrToRGB(unsigned char Y,
00053                                     unsigned char Cb,
00054                                     unsigned char Cr,
00055                                     unsigned char& R,
00056                                     unsigned char& G,
00057                                     unsigned char& B)
00058   {
00059     int r = (int)(Y + 1.4021 * (Cb - 128)),
00060         g = (int)(Y - 0.3456 * (Cr - 128) - 0.71448 * (Cb - 128)),
00061         b = (int)(Y + 1.7710 * (Cr - 128));
00062     if(r < 0) r = 0; else if(r > 255) r = 255;
00063     if(g < 0) g = 0; else if(g > 255) g = 255;
00064     if(b < 0) b = 0; else if(b > 255) b = 255;
00065     R = (unsigned char) r;
00066     G = (unsigned char) g;
00067     B = (unsigned char) b;
00068   }
00069 
00070   /** Converts an YCbCr image into an RGB image.
00071    *  @param ycbcrImage The given YCbCr image
00072    */
00073   void convertFromYCbCrToRGB(const Image& ycbcrImage);
00074 
00075   /** Converts an RGB image into an YUV image.
00076    *  @param rgbImage The given RGB image
00077    */
00078   void convertFromRGBToYUV(const Image& rgbImage);
00079 
00080   /** Converts an YCbCr pixel into an HSI pixel.
00081    *  @param Y The Y channel of the source pixel.
00082    *  @param Cb The Cb channel of the source pixel.
00083    *  @param Cr The Cr channel of the source pixel.
00084    *  @param H The H channel of the target pixel.
00085    *  @param S The S channel of the target pixel.
00086    *  @param I The I channel of the target pixel.
00087    */
00088   static void convertFromYCbCrToHSI(unsigned char Y,
00089                                     unsigned char Cb,
00090                                     unsigned char Cr,
00091                                     unsigned char& H,
00092                                     unsigned char& S,
00093                                     unsigned char& I)
00094   {
00095     const double sqrt3 = 1.732050808;
00096     unsigned char R,
00097                   G,
00098                   B;
00099     convertFromYCbCrToRGB(Y, Cb, Cr, R, G, B);
00100     I = R;
00101     if(G > I) I = G;
00102     if(B > I) I = B;
00103     if(I)
00104     {
00105       S = R;
00106       if(G < S) S = G;
00107       if(B < S) S = B;
00108       S = (unsigned char) (255 - 255 * S / I);
00109       if(S)
00110       {
00111         int h = int(atan2(sqrt3 * (G - B), 2 * R - G - B) / pi2 * 256);
00112         if(h > 256) h -= 256;
00113         else if(h < 0) h += 256;
00114         H = (unsigned char) h;
00115       }
00116       else
00117         H = 0;
00118     }
00119     else
00120       S = H = 0;
00121   }
00122 
00123   /** Converts an YCbCr image into an HSI image.
00124    *  @param ycrcbImage The given Ycrcb image
00125    */
00126   void convertFromYCbCrToHSI(const Image& ycrcbImage);
00127 
00128   /** Converts an YUV image into an TSL image.
00129    *  @param yuvImage The given YUV image
00130    */
00131   void convertFromYUVToTSL(const Image& yuvImage);
00132 
00133   /** Returns the high resolution y value of a pixel
00134    *  @param x The x coord. of the pixel in high resolution
00135    *  @param y The y coord. of the pixel in high resolution
00136    *  @return The y value of the pixel
00137    */
00138   unsigned char getHighResY(int x, int y) const;
00139 
00140   /** Sets the high resolution y values for one pixel in low resolution 
00141    * @param x The x coord. of the pixel
00142    * @param y The y coord. of the pixel
00143    * @param tl The y value of the top left subpixel
00144    * @param bl The y value of the bottom left subpixel
00145    * @param tr The y value of the top right subpixel
00146    * @param br The y value of the bottom right subpixel
00147    */
00148   void setHighResY(int x, int y, unsigned char tl, unsigned char bl, unsigned char tr, unsigned char br);
00149 
00150   /** Assignment operator
00151   * @param other The other Image that is assigned to this one
00152   * @return A reference to this object after the assignment.
00153   */
00154   Image& operator=(const Image& other) 
00155   {
00156     memcpy((void *)this, (const void *)&other, sizeof(Image));
00157     return *this;
00158   }
00159 
00160   /** representation for an image
00161   * height color width
00162   * point of origin is the upper left corner, height is positive downwards
00163   * and width positive to the right
00164   * the color values are in the order Y,U,V
00165   */
00166   unsigned char image[cameraResolutionHeight_ERS7][6][cameraResolutionWidth_ERS7];
00167 
00168   CameraInfo cameraInfo;
00169 
00170   /** the frame number of that image */
00171   unsigned long frameNumber;
00172 
00173   /** associated color table */
00174   const ColorTable* colorTable;
00175 
00176   /**
00177   * set values in CameraInfo according to image size
00178   */
00179   void setCameraInfo();
00180 };
00181 
00182 /**
00183  * Streaming operator that writes an Image to a stream.
00184  * @param stream The stream to write on.
00185  * @param image The Image object.
00186  * @return The stream.
00187  */ 
00188 Out& operator<<(Out& stream, const Image& image);
00189 
00190 /**
00191  * Streaming operator that reads a Image from a stream.
00192  * @param stream The stream to read from.
00193  * @param image The Image object.
00194  * @return The stream.
00195  */ 
00196 In& operator>>(In& stream,Image& image);
00197 
00198 #endif //__Image_h_
00199 
00200 /*
00201  * Change log :
00202  * 
00203  * $Log: Image.h,v $
00204  * Revision 1.3  2004/09/08 14:39:03  wachter
00205  * - Fixed some doxygen-errors
00206  *
00207  * Revision 1.2  2004/05/26 14:06:32  roefer
00208  * Corrected initialization of addition y channels in default constructor
00209  * Flag for simulated images added
00210  *
00211  * Revision 1.1.1.1  2004/05/22 17:25:50  cvsadm
00212  * created new repository GT2004_WM
00213  *
00214  * Revision 1.6  2004/05/01 17:09:33  roefer
00215  * Streamlined HSI stuff
00216  *
00217  * Revision 1.5  2004/04/27 17:22:06  thomas
00218  * added convertFromYCbCr2RGB for images
00219  *
00220  * Revision 1.4  2004/04/07 13:00:44  risler
00221  * ddd checkin after go04 - second part
00222  *
00223  * Revision 1.5  2004/04/07 11:44:05  risler
00224  * added sending low res images
00225  * added Image::setCameraInfo
00226  *
00227  * Revision 1.4  2004/04/06 13:19:35  risler
00228  * cleaned up and improved high resolution image support
00229  *
00230  * Revision 1.3  2004/03/29 20:45:16  risler
00231  * bugfix getHighResY
00232  *
00233  * Revision 1.2  2004/03/29 15:19:03  Marc
00234  * Intruduced the Black and White Image
00235  * Normal Images (not Jpeg) images were now send as Color Image with BW
00236  *
00237  * Revision 1.3  2003/12/30 20:12:03  roefer
00238  * Image size is now 208 x 160. Smaller images are placed in the upper left corner
00239  *
00240  * Revision 1.2  2003/12/15 11:47:07  juengel
00241  * Introduced CameraInfo
00242  *
00243  * Revision 1.1  2003/10/07 10:09:36  cvsadm
00244  * Created GT2004 (M.J.)
00245  *
00246  * Revision 1.2  2003/09/26 15:27:27  juengel
00247  * Renamed DataTypes to representations.
00248  *
00249  * Revision 1.1.1.1  2003/07/02 09:40:22  cvsadm
00250  * created new repository for the competitions in Padova from the 
00251  * tamara CVS (Tuesday 2:00 pm)
00252  *
00253  * removed unused solutions
00254  *
00255  * Revision 1.9  2003/03/10 18:20:44  dueffert
00256  * const cast warning removed
00257  *
00258  * Revision 1.8  2003/02/24 22:30:54  juengel
00259  * Added convertion methods for TSL and HSI
00260  *
00261  * Revision 1.7  2003/02/19 14:59:54  roefer
00262  * pColorTable -> colorTable
00263  *
00264  * Revision 1.6  2003/02/18 21:29:17  osterhues
00265  * Changed all instances of ColorTable64 to new base class ColorTable
00266  *
00267  * Revision 1.5  2003/01/09 13:07:16  jhoffman
00268  * no message
00269  *
00270  * Revision 1.4  2002/12/15 23:33:02  dueffert
00271  * rgb-yuv-convertion moved to Image
00272  *
00273  * Revision 1.3  2002/11/25 14:48:31  jhoffman
00274  * added "=" operator
00275  *
00276  * Revision 1.2  2002/09/17 23:55:20  loetzsch
00277  * - unraveled several datatypes
00278  * - changed the WATCH macro
00279  * - completed the process restructuring
00280  *
00281  * Revision 1.1  2002/09/10 15:26:40  cvsadm
00282  * Created new project GT2003 (M.L.)
00283  * - Cleaned up the /Src/DataTypes directory
00284  * - Removed Challenge Code
00285  * - Removed processing of incoming audio data
00286  * - Renamed AcousticMessage to SoundRequest
00287  *
00288  * Revision 1.3  2002/07/23 13:32:57  loetzsch
00289  * new streaming classes
00290  *
00291  * removed many #include statements
00292  *
00293  * Revision 1.2  2002/05/17 09:58:48  brunn
00294  * added comments discribing ordinate and coordinate of image
00295  *
00296  * Revision 1.1.1.1  2002/05/10 12:40:13  cvsadm
00297  * Moved GT2002 Project from ute to tamara.
00298  *
00299  * Revision 1.8  2002/04/02 13:10:18  dueffert
00300  * big change: odometryData and cameraMatrix in image now, old logfiles may be obsolete
00301  *
00302  * Revision 1.7  2001/12/12 20:21:12  petters
00303  * Streaming for SensorData / Image implemented; Conflict solved
00304  *
00305  * Revision 1.6  2001/12/12 18:08:55  loetzsch
00306  * Streaming- Operatoren für Bilder eingebaut, DebugKeyTable nicht- statisch gemacht, Debuggin Mechanismen weitergemacht, Bilder aus Logfiles in RobotControl anzeigen, Logfiles in HU1/Debug auf den Stick schreiben
00307  *
00308  * Revision 1.5  2001/12/10 17:47:05  risler
00309  * change log added
00310  *
00311  */

Generated on Thu Sep 23 19:57:36 2004 for GT2004 by doxygen 1.3.6