blejzz
blejzz

Reputation: 3349

color detection algorithm

Im developing a system that uses kinect for image processing. The system needs to detect certain objects based on their colors (from the kinect image).

My current solution is to use a window (of fixed size) and slide it through the whole image. I then count(in the window) the number of pixels that are green and compare it against some treshold. To check if the pixel is green i use a reference color (0x00FF00) and then calculate the distance of the current pixel to the reference color.

The algorithm goes like this:

referenceColor = 0x00FF00;
window_width = 10;
window_height = 10;
colorSum = 0;

COLOR_TRESHOLD = 20;
WINDOW_COLOR_TRESHOLD = 70;

foreach (pixel in image)
{
   colorSum = 0;
   for(i = 0; i < window_width; i++)
   { 
      for(j = 0; j < window_height; j++)
      { 
        //get the current pixel that is processed by the window
        curPixel = image.getPixelAt(i+pixel.indexX,j+pixel.indexY);
        // calculate the distance
        distance = sqrt((curPixel.r - referenceColor.r) ^ 2 + (curPixel.g - referenceColor.g) ^ 2 + (curPixel.b - referenceColor.b) ^ 2); 

        // check if distance smaller than the treshold
        if(distance <= COLOR_TRESHOLD) 
        {
           // pixel is green
           colorSum++;
        }
      }
   }
   // check if there are enough green pixels in the image
   if(colorSum > WINDOW_COLOR_TRESHOLD)
   {
       // green object detected
   }
}

The problem with this algorithm is that if the color is to dark/bright (due to sunlight/reflections) it fails (and i have to change the tresholds to get good detection). Ideally i would like to archive that every green pixel/object will get detected (regardless of how bright/dark it is). Does any know any good (robust) algorithm to archive this? Would appreciate a point in the right direction.

Thanks.

Upvotes: 2

Views: 9919

Answers (0)

Related Questions