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

# Modules/ImageProcessor/VLCImageProcessor/VLCColorSpace.cpp

Go to the documentation of this file.

    00001 #include "VLCColorSpace.h"
    00002
    00003 ColorSpace::ColorSpace ()
    00004 {
    00005   int i;
    00006
    00007   for (i = 0; i < numOfColors; i++)
    00008     colorCount[i] = 0.0;
    00009
    00010   for (i = 0; i < numOfColors; i++)
    00011         yCount[i] = 0.0;
    00012
    00013   y = 0;
    00014   dY = 0;
    00015 };
    00016
    00017 void ColorSpace::Normalize ()
    00018 {
    00019   int i;
    00020   double sum = this->Sum ();
    00021
    00022   if (sum == 0)
    00023     return;
    00024
    00025   for (i = 0; i < numOfColors; i++)
    00026     colorCount[i] /= sum;
    00027
    00028   for (i = 0; i < BRIGHTNESS_LEVELS; i++)
    00029         yCount[i] /= sum;
    00030
    00031   y /= sum;
    00032   dY /= sum;
    00033 };
    00034
    00035 double ColorSpace::Sum ()
    00036 {
    00037   double result = 0;
    00038
    00039   for (int i = 0; i < numOfColors; i++)
    00040     result += colorCount[i];
    00041
    00042   return result;
    00043 };
    00044
    00045 void ColorSpace::AddSample (colorClass color, double brightness, double dY)
    00046 {
    00047   this->colorCount[color]++;
    00048   this->y += brightness;
    00049   this->dY += fabs (dY);
    00050 };
    00051
    00052 colorClass ColorSpace::getMajorColor ()
    00053 {
    00054   double maxValue = 0;
    00055   colorClass result = noColor;
    00056
    00057   for (int i = 0; i < numOfColors; i++)
    00058   {
    00059     if (maxValue < colorCount[i])
    00060     {
    00061       result = (colorClass)i;
    00062       maxValue = colorCount[i];
    00063     }
    00064   }
    00065
    00066   return result;
    00067 };
    00068
    00069
    00070 /*
    00071 * ------------------------------------------------------------------------------------------------------
    00072 */
    00073 RobotDirection::RobotDirection ()
    00074 {
    00075   int i;
    00076
    00077   for (i = 0; i < DIRECTION_LEVELS; i++)
    00078     directionCount[i] = 0;
    00079 };
    00080
    00081 void RobotDirection::AddSample (double direction, int weight)
    00082 {
    00083   while (direction >= pi2)
    00084     direction -= pi2;
    00085
    00086   while (direction < 0)
    00087     direction += pi2;
    00088
    00089   int dir = (int)((direction / pi2) * ((double)DIRECTION_LEVELS));
    00090
    00091   directionCount[dir] += weight;
    00092 };
    00093
    00094 double RobotDirection::getDirection ()
    00095 {
    00096   double result = 0;
    00097   double maxValue = 0;
    00098
    00099   int i;
    00100
    00101   for (i = 0; i < DIRECTION_LEVELS; i++)
    00102     if (directionCount[i] > maxValue)
    00103     {
    00104       maxValue = directionCount[i];
    00105       result = pi2 * ((double)i) / ((double)DIRECTION_LEVELS);
    00106     };
    00107
    00108   return result;
    00109 };
    00110
    00111 double RobotDirection::getReliability ()
    00112 {
    00113   double maxValue = 0;
    00114   double sum = 0;
    00115
    00116   int i;
    00117
    00118   for (i = 0; i < DIRECTION_LEVELS; i++)
    00119   {
    00120     if (directionCount[i] > maxValue)
    00121     {
    00122       maxValue = directionCount[i];
    00123     }
    00124
    00125     sum += directionCount[i];
    00126   };
    00127
    00128   if (sum == 0)
    00129     return 0;
    00130
    00131   return maxValue / ((double)sum);
    00132 };