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

Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h

Go to the documentation of this file.
00001 /**
00002 * @file Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h
00003 * 
00004 * This file contains a class that represents a table used for color correction.
00005 * It is a mixture among the BB2004, DDD2004 and MSH2004 correction.
00006 * Everything is static so it is loaded only once in the simulator.
00007 *
00008 * @author <A href="mailto:walter.nistico@uni-dortmund.de">Walter Nistico</A>
00009 * @author Max Risler
00010 * @author <A href="mailto:roefer@tzi.de">Thomas Röfer</A>
00011 */
00012 
00013 #ifndef __ColorCorrector_h_
00014 #define __ColorCorrector_h_
00015 
00016 #include "Representations/Perception/Image.h"
00017 
00018 #define MSH
00019 
00020 /**
00021 * @class ColorCorrector
00022 * The class represents a table for color correction.
00023 */
00024 class ColorCorrector
00025 {
00026 private:
00027   enum {maxRadius = 140, centerRadius = 10};
00028   static unsigned char radiusTable[cameraResolutionHeight_ERS7][cameraResolutionWidth_ERS7]; /**< The radius table. */
00029   static unsigned char correctionTable[maxRadius][256][3]; /**< The correction table. */
00030 
00031 #ifdef MSH
00032   enum {maxRadialOrder = 10, maxColorOrder = 10};
00033   static int radialOrder;
00034   static int colorOrder;
00035   static double radialP[3 * maxRadialOrder];
00036   static double colorP[3 * maxColorOrder];
00037 
00038   static unsigned char colorDistortionCorrection(const unsigned char radius_i, const unsigned char color, 
00039                                                  const unsigned char channel);
00040 #endif
00041 
00042 #ifdef _WIN32  
00043   static unsigned char distortionTable[maxRadius][256][3]; /**< The distortion table. */
00044 #endif
00045   static bool loaded; /**< Determines whether the corrector has already been loaded. */
00046 
00047   /**
00048   * The function calculates the corresponding radius for an image coordinate.
00049   * @param x The x coordinate of a pixel.
00050   * @param y The y coordinate of a pixel.
00051   * @return The distance from the center of the image.
00052   */
00053   static unsigned char calcRadius(int x, int y)
00054   {
00055     int r = (int) (Vector2<double>(x - cameraResolutionWidth_ERS7 / 2,
00056                                    y - cameraResolutionHeight_ERS7 / 2).abs() - centerRadius);
00057     if(r < 0)
00058       r = 0;
00059     return (unsigned char) r;
00060   }
00061 
00062 public:
00063   /**
00064   * The functions returns a corrected intensity of a pixel.
00065   * @param x The x coordinate of the pixel.
00066   * @param y The y coordinate of the pixel.
00067   * @param c The color channel corrected.
00068   * @param intensity The intensity of the pixel in color channel c.
00069   * @return The corrected intensity.
00070   */
00071   static unsigned char correct(const int x, const int y, 
00072                                const int c, const unsigned char intensity)
00073   {
00074     return correctionTable[radiusTable[y][x]][intensity][c];
00075   }
00076 
00077   /**
00078   * The functions returns the corrected color of a pixel.
00079   * @param x The x coordinate of the pixel.
00080   * @param y The y coordinate of the pixel.
00081   * @param intensityY The intensity of the pixel in color channel Y.
00082   * @param intensityU The intensity of the pixel in color channel U.
00083   * @param intensityV The intensity of the pixel in color channel V.
00084   */
00085   static void correct(const int x, const int y, 
00086                       unsigned char& intensityY, 
00087                       unsigned char& intensityU, 
00088                       unsigned char& intensityV)
00089   {
00090     int radius = radiusTable[y][x];
00091     intensityY = correctionTable[radius][intensityY][0];
00092     intensityU = correctionTable[radius][intensityU][1];
00093     intensityV = correctionTable[radius][intensityV][2];
00094   }
00095 
00096   /**
00097   * The functions corrects all pixels of an image.
00098   * @param image The image that is corrected.
00099   */
00100   static void correct(Image& image);
00101 
00102 #ifdef _WIN32
00103   /**
00104   * The functions returns a disturbed color of a pixel.
00105   * @param x The x coordinate of the pixel.
00106   * @param y The y coordinate of the pixel.
00107   * @param intensityY The intensity of the pixel in color channel Y.
00108   * @param intensityU The intensity of the pixel in color channel U.
00109   * @param intensityV The intensity of the pixel in color channel V.
00110   */
00111   static void distort(const int x, const int y, 
00112                       unsigned char& intensityY, 
00113                       unsigned char& intensityU, 
00114                       unsigned char& intensityV)
00115   {
00116     int radius = radiusTable[y][x];
00117     intensityY = distortionTable[radius][intensityY][0];
00118     intensityU = distortionTable[radius][intensityU][1];
00119     intensityV = distortionTable[radius][intensityV][2];
00120   }
00121 
00122   /**
00123   * The functions disturbs all pixels of an image.
00124   * @param image The image that is disturbed.
00125   */
00126   static void distort(Image& image);
00127 
00128 #endif
00129 
00130   /**
00131   * Loads the calibration image and computes the lookup table
00132   */
00133   static void load();
00134 
00135   /**
00136   * The function disables the color correction.
00137   * The table is cleared.
00138   */
00139   static void disable();
00140 };
00141 
00142 #endif// __ColorCorrector_h_
00143 
00144 /*
00145 * Change log :
00146 * 
00147 * $Log: ColorCorrector.h,v $
00148 * Revision 1.1.1.1  2004/05/22 17:19:47  cvsadm
00149 * created new repository GT2004_WM
00150 *
00151 * Revision 1.4  2004/05/15 14:31:21  nistico
00152 * ColorCorrector now by default loads coefficients from Config/ folder.
00153 * If other coefficients are present in the folder pointed by location.cfg,
00154 * these override the default ones.
00155 *
00156 * Revision 1.3  2004/04/24 08:14:03  roefer
00157 * Author name was missing
00158 *
00159 * Revision 1.2  2004/04/22 14:28:46  roefer
00160 * ColorCorrector now supports MSH and DDD color correction
00161 *
00162 * Revision 1.1  2004/04/17 21:50:51  roefer
00163 * New color corrector (BB/DDD mix) used in BB2004ImageProcessor and Simulator
00164 * Displaying corrected images as debug image
00165 *
00166 */

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