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

# Modules/ImageProcessor/ImageProcessorTools/ColorTableReferenceColor.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file ColorTableReferenceColor.cpp
    00003 * Implementation of class ColorTableReferenceColor.
    00004 *
    00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00006 */
    00007
    00008 #include "ColorTableReferenceColor.h"
    00009 #include "Platform/SystemCall.h"
    00010 #include "Tools/Math/Common.h"
    00011
    00012
    00013 ColorTableReferenceColor::ColorTableReferenceColor()
    00014 {
    00015   clear();
    00016 }
    00017
    00018 ColorTableReferenceColor::~ColorTableReferenceColor()
    00019 {
    00020 }
    00021
    00022 void ColorTableReferenceColor::clear()
    00023 {
    00024   greenMin[0] = 255; greenMin[1] = 255; greenMin[2] = 255;
    00025   greenMax[0] = 0; greenMax[1] = 0; greenMax[2] = 0;
    00026   setGreen();
    00027   greenIsValid = false;
    00028   setGreenCounter = 0;
    00029 }
    00030
    00031
    00032 int ColorTableReferenceColor::getGreenMin(int channel) const
    00033 {
    00034   return greenMin[channel];
    00035 }
    00036
    00037 int ColorTableReferenceColor::getGreenMax(int channel) const
    00038 {
    00039   return greenMax[channel];
    00040 }
    00041
    00042 void ColorTableReferenceColor::setGreenMin(int channel, int value)
    00043 {
    00044   greenMin[channel] = value;
    00045   setGreen();
    00046 }
    00047
    00048 void ColorTableReferenceColor::setGreenMax(int channel, int value)
    00049 {
    00050   greenMax[channel] = value;
    00051   setGreen();
    00052 }
    00053
    00054 void ColorTableReferenceColor::expandGreen(int greenMin[3], int greenMax[3])
    00055 {
    00056   if(greenMin[0] < this->greenMin[0]) this->greenMin[0] = greenMin[0];
    00057   if(greenMin[1] < this->greenMin[1]) this->greenMin[1] = greenMin[1];
    00058   if(greenMin[2] < this->greenMin[2]) this->greenMin[2] = greenMin[2];
    00059
    00060   if(greenMax[0] > this->greenMax[0]) this->greenMax[0] = greenMax[0];
    00061   if(greenMax[1] > this->greenMax[1]) this->greenMax[1] = greenMax[1];
    00062   if(greenMax[2] > this->greenMax[2]) this->greenMax[2] = greenMax[2];
    00063   setGreen();
    00064 }
    00065
    00066 int ColorTableReferenceColor::getAverageGreen(int channel) const
    00067 {
    00068   return averageGreen[channel];
    00069 }
    00070
    00071 void ColorTableReferenceColor::setGreen()
    00072 {
    00073   setGreenCounter++;
    00074   if(setGreenCounter > 5) greenIsValid = true;
    00075   int greenRange[3];
    00076   greenRange[0] = greenMax[0] - greenMin[0];
    00077   greenRange[1] = greenMax[1] - greenMin[1];
    00078   greenRange[2] = greenMax[2] - greenMin[2];
    00079
    00080   averageGreen[0] = (greenMax[0] + greenMin[0]) / 2;
    00081   averageGreen[1] = (greenMax[1] + greenMin[1]) / 2;
    00082   averageGreen[2] = (greenMax[2] + greenMin[2]) / 2;
    00083
    00084 //  skyblueAutoMin[0] = (int)(greenMin[0] * 0.8);
    00085 //  skyblueAutoMax[0] = min(255, greenMax[0] * 2);
    00086   skyblueAutoMin[0] = 0;
    00087   skyblueAutoMax[0] = 255;
    00088   skyblueAutoMax[1] = averageGreen[1];
    00089   skyblueAutoMin[2] = greenMax[2];
    00090
    00091 //  yellowAutoMin[0] = greenMin[0] / 3;
    00092   yellowAutoMax[0] = min(255, greenMax[0] * 2);
    00093   yellowAutoMin[0] = 0;
    00094 //  yellowAutoMax[0] = 255;
    00095   yellowAutoMin[1] = averageGreen[1];
    00096   yellowAutoMax[2] = greenMin[2] - 10;
    00097 //  yellowAutoMin[1] = greenMax[1];
    00098 //  yellowAutoMax[2] = greenMin[2];
    00099
    00100 //  orangeAutoMin[0] = averageGreen[0] - 90;
    00101 //  orangeAutoMax[0] = averageGreen[0] + 120;
    00102   orangeAutoMin[0] = 0;
    00103   orangeAutoMax[0] = 255;
    00104   orangeAutoMin[1] = averageGreen[1] + 40;
    00105   orangeAutoMax[2] = averageGreen[2];
    00106 /*
    00107 newSegment.averageIntensity[0] > colorTableReferenceColor.getAverageGreen(0) - 90 &&
    00108 newSegment.averageIntensity[0] < colorTableReferenceColor.getAverageGreen(0) + 120 &&
    00109 newSegment.averageIntensity[1] > colorTableReferenceColor.getAverageGreen(1) + 40 &&
    00110 newSegment.averageIntensity[2] < colorTableReferenceColor.getAverageGreen(2) - 0 &&
    00111 */
    00112
    00113   pinkAutoMin[0] = averageGreen[0];
    00114   pinkAutoMin[1] = averageGreen[1] + 20;
    00115   pinkAutoMin[2] = averageGreen[2];
    00116
    00117   whiteAutoMin[0] = averageGreen[0];
    00118   whiteAutoMin[1] = averageGreen[1] - 2 * greenRange[1];
    00119   whiteAutoMax[1] = averageGreen[1] + 2 * greenRange[1];
    00120   whiteAutoMin[2] = averageGreen[2] - 2 * greenRange[2];
    00121   whiteAutoMax[2] = averageGreen[2] + 2 * greenRange[2];
    00122
    00123   whiteFixedMin[0] = 180;
    00124   whiteFixedMin[1] = 127 - 20;
    00125   whiteFixedMax[1] = 127 + 50;
    00126   whiteFixedMin[2] = 127 - 70;
    00127   whiteFixedMax[2] = 127 + 30;
    00128 }
    00129
    00130 colorClass ColorTableReferenceColor::getColorClass
    00131 (
    00132  const unsigned char y,
    00133  const unsigned char u,
    00134  const unsigned char v
    00135  ) const
    00136 {
    00137   colorClass toReturn = noColor;
    00138   if(
    00139     // green of the field
    00140     greenIsValid &&
    00141     y >= greenMin[0] && y <= greenMax[0] &&
    00142     u >= greenMin[1] && u <= greenMax[1] &&
    00143     v >= greenMin[2] && v <= greenMax[2]
    00144     )
    00145   {
    00146     return green;
    00147   }
    00148   if(
    00149     greenIsValid &&
    00150 //    y > skyblueAutoMin[0] &&
    00151 //    y < skyblueAutoMax[0] &&
    00152     u < skyblueAutoMax[1] &&
    00153     v > skyblueAutoMin[2])
    00154   {
    00155     return skyblue;
    00156   }
    00157   if(
    00158     greenIsValid &&
    00159     y > yellowAutoMin[0] &&
    00160     y < yellowAutoMax[0] &&
    00161     u > yellowAutoMin[1] &&
    00162     v < yellowAutoMax[2]
    00163     )
    00164   {
    00165 //    return yellow;
    00166     toReturn = yellow;
    00167   }
    00168   if(
    00169     greenIsValid &&
    00170 //    y > orangeAutoMin[0] &&
    00171 //    y < orangeAutoMax[0] &&
    00172     u > orangeAutoMin[1] &&
    00173     v < orangeAutoMax[2]
    00174     )
    00175   {
    00176     if (toReturn == yellow) return yellowOrange;
    00177     return orange;
    00178   }
    00179   if(toReturn == yellow)
    00180   {
    00181     return toReturn;
    00182   }
    00183   if(
    00184 //    y > whiteMin[0] &&
    00185 //    u > whiteMin[1] && u < whiteMax[1] &&
    00186 //    v > whiteMin[2] && v < whiteMax[2]
    00187 //    ||
    00188     y > whiteFixedMin[0] &&
    00189     u > whiteFixedMin[1] && u < whiteFixedMax[1] &&
    00190     v > whiteFixedMin[2] && v < whiteFixedMax[2]
    00191     )
    00192   {
    00193     return white;
    00194   }
    00195   if(
    00196     greenIsValid &&
    00197     y > pinkAutoMin[0] &&
    00198     u > pinkAutoMin[1] &&
    00199     v > pinkAutoMin[2]
    00200     )
    00201   {
    00202     return pink;
    00203   }
    00204   return noColor;
    00205 }
    00206
    00207 void ColorTableReferenceColor::generateColorClassImage
    00208 (
    00209  const Image& image,
    00210  ColorClassImage& colorClassImage) const
    00211 {
    00212   colorClass color;
    00213   colorClassImage.width = image.cameraInfo.resolutionWidth;
    00214   colorClassImage.height = image.cameraInfo.resolutionHeight;
    00215
    00216   for (register int y = 0; y < image.cameraInfo.resolutionHeight; y++)
    00217   {
    00218     for (register int x = 0; x < image.cameraInfo.resolutionWidth; x++)
    00219     {
    00220       color = getColorClass(image.image[y][0][x],image.image[y][1][x],image.image[y][2][x]);
    00221       colorClassImage.image[y][x] = color;
    00222     }
    00223   }
    00224 }
    00225
    00226 In& operator>>(In& stream, ColorTableReferenceColor& colorTableReferenceColor)
    00227 {
    00228   int greenMin;
    00229   int greenMax;
    00230   for(int channel = 0; channel < 3; channel++)
    00231   {
    00232     stream >> greenMin;
    00233     stream >> greenMax;
    00234     colorTableReferenceColor.setGreenMin(channel, greenMin);
    00235     colorTableReferenceColor.setGreenMax(channel, greenMax);
    00236   }
    00237   return stream;
    00238 }
    00239
    00240 Out& operator<<(Out& stream, const ColorTableReferenceColor& colorTableReferenceColor)
    00241 {
    00242   for(int channel = 0; channel < 3; channel++)
    00243   {
    00244     stream << colorTableReferenceColor.getGreenMin(channel);
    00245     stream << colorTableReferenceColor.getGreenMax(channel);
    00246   }
    00247   return stream;
    00248 }