private static int assignType(int color)
    {
        int type = BACKGROUND;
        int minDist = 999999;
      
        
        // extract the r,g,b components
        int r = color >> 10;
        int g = (color >> 5) & 31;
        int b = color & 31;
        
        // convert to 8 bit per component
        r = r << 3;
        g = g << 3;
        b = b << 3;
        
        // special cases where pixel is grayscale
        if (r == g && r == b)
        {
            if (r >= 88 && r <= 208)
                return STONE;
            if (r > 232)
                return TRAJECTORY;
            if (r == 64)
                return BLACK_BIRD;
        }
     
        for (int i = 0; i < _trainData.length; i++)
        {
            // calculate squared distance between the color and training data
            int d1 = r - _trainData[i][0];
            int d2 = g - _trainData[i][1];
            int d3 = b - _trainData[i][2];
            int dist = d1 * d1 + d2 * d2 + d3 * d3;
            
            // assign pixel to the types with shortest distance
            if (dist < minDist && dist < MAX_DIST*MAX_DIST)
            {
                minDist = dist;
                type = _trainData[i][3];
            }
        }
        return type;
    }