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 #include "Platform/GTAssert.h"
    00018
    00019 #define MSH
    00020
    00021 /**
    00022 * @class ColorCorrector
    00023 * The class represents a table for color correction.
    00024 */
    00025 class ColorCorrector
    00026 {
    00027 private:
    00028   enum {maxRadius = 140, centerRadius = 10};
    00029   unsigned char radiusTable[cameraResolutionHeight_ERS7][cameraResolutionWidth_ERS7]; /**< The radius table. Per (simulated) robot. */
    00030   static unsigned char correctionTable[maxRadius + 1][256][3]; /**< The correction table. */
    00031
    00032 #ifdef MSH
    00033   enum {maxRadialOrder = 10, maxColorOrder = 10};
    00034   static int radialOrder;
    00035   static int colorOrder;
    00036   static double radialP[3 * maxRadialOrder];
    00037   static double colorP[3 * maxColorOrder];
    00038
    00039   static unsigned char colorDistortionCorrection(const unsigned char radius_i, const unsigned char color,
    00040                                                  const unsigned char channel);
    00041 #endif
    00042
    00043 #ifdef _WIN32
    00044   static unsigned char distortionTable[maxRadius + 1][256][3]; /**< The distortion table. */
    00045 #endif
    00046   static bool loaded; /**< Determines whether the corrector has already been loaded. */
    00047
    00048   /**
    00049   * The function calculates the corresponding radius for an image coordinate.
    00050   * @param x The x coordinate of a pixel.
    00051   * @param y The y coordinate of a pixel.
    00052   * @return The distance from the center of the image.
    00053   */
    00054   static unsigned char calcRadius(int x, int y)
    00055   {
    00056     int r = (int) (Vector2<double>(x - cameraResolutionWidth_ERS7 / 2,
    00057                                    y - cameraResolutionHeight_ERS7 / 2).abs() - centerRadius);
    00058     if(r < 0)
    00059       r = 0;
    00060     return (unsigned char) r;
    00061   }
    00062
    00063 public:
    00064   /**
    00065   * Default constructor.
    00066   */
    00067   ColorCorrector() {load();}
    00068
    00069   /**
    00070   * The functions returns a corrected intensity of a pixel.
    00071   * @param x The x coordinate of the pixel.
    00072   * @param y The y coordinate of the pixel.
    00073   * @param c The color channel corrected.
    00074   * @param intensity The intensity of the pixel in color channel c.
    00075   * @return The corrected intensity.
    00076   */
    00077   inline unsigned char correct(const int x, const int y,
    00078                                const int c, const unsigned char intensity) const
    00079   {
    00080 //    ASSERT(x >= 0 && y >= 0);
    00081     if ((x >= 0) && (y >= 0))
    00082       return correctionTable[radiusTable[y][x]][intensity][c];
    00083     else
    00084       return 0;
    00085   }
    00086
    00087   /**
    00088   * The functions returns the corrected color of a pixel.
    00089   * @param x The x coordinate of the pixel.
    00090   * @param y The y coordinate of the pixel.
    00091   * @param intensityY The intensity of the pixel in color channel Y.
    00092   * @param intensityU The intensity of the pixel in color channel U.
    00093   * @param intensityV The intensity of the pixel in color channel V.
    00094   */
    00095   inline void correct(const int x, const int y,
    00096                       unsigned char& intensityY,
    00097                       unsigned char& intensityU,
    00098                       unsigned char& intensityV) const
    00099   {
    00100     int radius = radiusTable[y][x];
    00101     intensityY = correctionTable[radius][intensityY][0];
    00102     intensityU = correctionTable[radius][intensityU][1];
    00103     intensityV = correctionTable[radius][intensityV][2];
    00104   }
    00105
    00106   /**
    00107   * The functions corrects all pixels of an image.
    00108   * @param image The image that is corrected.
    00109   */
    00110   void correct(Image& image) const;
    00111
    00112 #ifdef _WIN32
    00113   /**
    00114   * The functions returns a disturbed color of a pixel.
    00115   * @param x The x coordinate of the pixel.
    00116   * @param y The y coordinate of the pixel.
    00117   * @param intensityY The intensity of the pixel in color channel Y.
    00118   * @param intensityU The intensity of the pixel in color channel U.
    00119   * @param intensityV The intensity of the pixel in color channel V.
    00120   */
    00121   void distort(const int x, const int y,
    00122                       unsigned char& intensityY,
    00123                       unsigned char& intensityU,
    00124                       unsigned char& intensityV) const
    00125   {
    00126     int radius = radiusTable[y][x];
    00127     intensityY = distortionTable[radius][intensityY][0];
    00128     intensityU = distortionTable[radius][intensityU][1];
    00129     intensityV = distortionTable[radius][intensityV][2];
    00130   }
    00131
    00132   /**
    00133   * The functions disturbs all pixels of an image.
    00134   * @param image The image that is disturbed.
    00135   */
    00136   void distort(Image& image) const;
    00137
    00138 #endif
    00139
    00140 private:
    00141   /**
    00142   * Loads the calibration image and computes the lookup table
    00143   */
    00144   void load();
    00145
    00146   /**
    00147   * The function disables the color correction.
    00148   * The table is cleared.
    00149   */
    00150   void disable();
    00151 };
    00152
    00153 #endif// __ColorCorrector_h_