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

# Modules/ImageProcessor/ImageProcessorTools/ColorSpaceUsageCounter.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file ColorSpaceUsageCounter.cpp
    00003 * Implementation of class ColorSpaceUsageCounter.
    00004 *
    00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00006 */
    00007
    00008 #include "ColorSpaceUsageCounter.h"
    00009 #include "Tools/Math/Histogram.h"
    00010
    00011 void ColorSpaceUsageCounter::generateImage
    00012 (
    00013  const Image& image,
    00014  Image& resultImage) const
    00015 {
    00016 //  Histogram colorFrequencyHistogram(Histogram::colorFrequency);
    00017   for (int y = 0; y < image.cameraInfo.resolutionHeight; y++)
    00018   {
    00019     for (int x = 0; x < image.cameraInfo.resolutionWidth; x++)
    00020     {
    00021       if(maxCount == 0) resultImage.image[y][0][x] = 0;
    00022       else
    00023       {
    00024         resultImage.image[y][0][x] =
    00025           count[image.image[y][0][x]/16][image.image[y][1][x]/16][image.image[y][2][x]/16] * 255 / maxCount;
    00026       }
    00027       resultImage.image[y][1][x] = 127;
    00028       resultImage.image[y][2][x] = 127;
    00029 /*      if(resultImage.image[y][0][x] < 80)
    00030       {
    00031         resultImage.image[y][0][x] = 0;
    00032         resultImage.image[y][1][x] = 0;
    00033         resultImage.image[y][2][x] = 0;
    00034       }
    00035 */
    00036 //      colorFrequencyHistogram.add(count[image.image[y][0][x]/16][image.image[y][1][x]/16][image.image[y][2][x]/16] * 255 / maxCount);
    00037     }
    00038   }
    00039 /*  for (y = 0; y < 64; y++)
    00040   {
    00041     for (u = 0; u < 64; u++)
    00042     {
    00043       for (v = 0; v < 64; v++)
    00044       {
    00045         if(count[y][u][v] != 0)
    00046           colorFrequencyHistogram.add(count[y][u][v] * 255 / maxCount);
    00047       }
    00048     }
    00049   }
    00050   */
    00051 //  INFO(sendHistogram_colorFrequency, idHistogram, bin, colorFrequencyHistogram);
    00052 }
    00053
    00054 ColorSpaceUsageCounter::~ColorSpaceUsageCounter()
    00055 {
    00056 }
    00057
    00058 ColorSpaceUsageCounter::ColorSpaceUsageCounter()
    00059 {
    00060   reset();
    00061 }
    00062
    00063 void ColorSpaceUsageCounter::addColor
    00064 (
    00065  unsigned char y,
    00066  unsigned char u,
    00067  unsigned char v
    00068  )
    00069 {
    00070   y /= 16; u /= 16; v /= 16;
    00071
    00072   count[y][u][v] += 1;
    00073   if (count[y][u][v] > maxCount) maxCount = count[y][u][v];
    00074 }
    00075
    00076 void ColorSpaceUsageCounter::addColor
    00077 (
    00078  unsigned char y,
    00079  unsigned char u,
    00080  unsigned char v,
    00081  unsigned char range
    00082  )
    00083 {
    00084   y /= 16; u /= 16; v /= 16;
    00085
    00086   if (y < range / 2) y = range / 2;
    00087   if (u < range / 2) u = range / 2;
    00088   if (v < range / 2) v = range / 2;
    00089
    00090   if (y - range / 2 + range > 63) y = 63 + range / 2 - range;
    00091   if (u - range / 2 + range > 63) u = 63 + range / 2 - range;
    00092   if (v - range / 2 + range > 63) v = 63 + range / 2 - range;
    00093
    00094   for(unsigned char currentY = y - range / 2; currentY < y - range / 2 + range; currentY++)
    00095   {
    00096     for(unsigned char currentU = u - range / 2; currentU < u - range / 2 + range; currentU++)
    00097     {
    00098       for(unsigned char currentV = v - range / 2; currentV < v - range / 2 + range; currentV++)
    00099       {
    00100         count[currentY][currentU][currentV] += 1;
    00101         if (count[currentY][currentU][currentV] > maxCount) maxCount = count[currentY][currentU][currentV];
    00102       }
    00103     }
    00104   }
    00105 }
    00106
    00107 bool ColorSpaceUsageCounter::isColorFrequent
    00108 (
    00109  unsigned char y,
    00110  unsigned char u,
    00111  unsigned char v,
    00112  int threshold
    00113  )
    00114 {
    00115   if(maxCount == 0) return false;
    00116   y /= 16; u /= 16; v /= 16;
    00117   return count[y][u][v] * 100 / maxCount > threshold;
    00118 }
    00119
    00120 void ColorSpaceUsageCounter::reset()
    00121 {
    00122   memset(count, 0, sizeof(count));
    00123   maxCount = 0;
    00124 }