Esempio n. 1
0
void CvHaarEvaluator::FeatureHaar::generateRandomFeature( Size patchSize )
{
  cv::Point2i position;
  Size baseDim;
  Size sizeFactor;
  int area;

  //Size minSize = Size( 3, 3 );
  int minArea = 9;

  bool valid = false;
  while ( !valid )
  {
    //choose position and scale
    position.y = rand() % ( patchSize.height );
    position.x = rand() % ( patchSize.width );

    baseDim.width = (int) ( ( 1 - sqrt( 1 - (float) rand() / RAND_MAX ) ) * patchSize.width );
    baseDim.height = (int) ( ( 1 - sqrt( 1 - (float) rand() / RAND_MAX ) ) * patchSize.height );

    //select types
    //float probType[11] = {0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0950f};
    float probType[11] =
    { 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
    float prob = (float) rand() / RAND_MAX;

    if( prob < probType[0] )
    {
      //check if feature is valid
      sizeFactor.height = 2;
      sizeFactor.width = 1;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 1;
      m_numAreas = 2;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );

      valid = true;

    }
    else if( prob < probType[0] + probType[1] )
    {
      //check if feature is valid
      sizeFactor.height = 1;
      sizeFactor.width = 2;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 2;
      m_numAreas = 2;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;

    }
    else if( prob < probType[0] + probType[1] + probType[2] )
    {
      //check if feature is valid
      sizeFactor.height = 4;
      sizeFactor.width = 1;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 3;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -2;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = 2 * baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y + 3 * baseDim.height;
      m_areas[2].x = position.x;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] )
    {
      //check if feature is valid
      sizeFactor.height = 1;
      sizeFactor.width = 4;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 3;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -2;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = 2 * baseDim.width;
      m_areas[2].y = position.y;
      m_areas[2].x = position.x + 3 * baseDim.width;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] )
    {
      //check if feature is valid
      sizeFactor.height = 2;
      sizeFactor.width = 2;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 5;
      m_numAreas = 4;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -1;
      m_weights[2] = -1;
      m_weights[3] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y + baseDim.height;
      m_areas[2].x = position.x;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_areas[3].y = position.y + baseDim.height;
      m_areas[3].x = position.x + baseDim.width;
      m_areas[3].height = baseDim.height;
      m_areas[3].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] )
    {
      //check if feature is valid
      sizeFactor.height = 3;
      sizeFactor.width = 3;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 6;
      m_numAreas = 2;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -9;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = 3 * baseDim.height;
      m_areas[0].width = 3 * baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_initMean = -8 * 128;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] + probType[6] )
    {
      //check if feature is valid
      sizeFactor.height = 3;
      sizeFactor.width = 1;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 7;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -2;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y + baseDim.height * 2;
      m_areas[2].x = position.x;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] + probType[6] + probType[7] )
    {
      //check if feature is valid
      sizeFactor.height = 1;
      sizeFactor.width = 3;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;

      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;

      if( area < minArea )
        continue;

      m_type = 8;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -2;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y;
      m_areas[2].x = position.x + 2 * baseDim.width;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] + probType[6] + probType[7] + probType[8] )
    {
      //check if feature is valid
      sizeFactor.height = 3;
      sizeFactor.width = 3;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 9;
      m_numAreas = 2;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -2;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = 3 * baseDim.height;
      m_areas[0].width = 3 * baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_initMean = 0;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob
        < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] + probType[6] + probType[7] + probType[8] + probType[9] )
    {
      //check if feature is valid
      sizeFactor.height = 3;
      sizeFactor.width = 1;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 10;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -1;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x;
      m_areas[1].y = position.y + baseDim.height;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y + baseDim.height * 2;
      m_areas[2].x = position.x;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 128;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else if( prob
        < probType[0] + probType[1] + probType[2] + probType[3] + probType[4] + probType[5] + probType[6] + probType[7] + probType[8] + probType[9]
            + probType[10] )
    {
      //check if feature is valid
      sizeFactor.height = 1;
      sizeFactor.width = 3;
      if( position.y + baseDim.height * sizeFactor.height >= patchSize.height || position.x + baseDim.width * sizeFactor.width >= patchSize.width )
        continue;
      area = baseDim.height * sizeFactor.height * baseDim.width * sizeFactor.width;
      if( area < minArea )
        continue;

      m_type = 11;
      m_numAreas = 3;
      m_weights.resize( m_numAreas );
      m_weights[0] = 1;
      m_weights[1] = -1;
      m_weights[2] = 1;
      m_areas.resize( m_numAreas );
      m_areas[0].x = position.x;
      m_areas[0].y = position.y;
      m_areas[0].height = baseDim.height;
      m_areas[0].width = baseDim.width;
      m_areas[1].x = position.x + baseDim.width;
      m_areas[1].y = position.y;
      m_areas[1].height = baseDim.height;
      m_areas[1].width = baseDim.width;
      m_areas[2].y = position.y;
      m_areas[2].x = position.x + 2 * baseDim.width;
      m_areas[2].height = baseDim.height;
      m_areas[2].width = baseDim.width;
      m_initMean = 128;
      m_initSigma = INITSIGMA( m_numAreas );
      valid = true;
    }
    else
    CV_Error(CV_StsAssert, "");
  }

  m_initSize = patchSize;
  m_curSize = m_initSize;
  m_scaleFactorWidth = m_scaleFactorHeight = 1.0f;
  m_scaleAreas.resize( m_numAreas );
  m_scaleWeights.resize( m_numAreas );
  for ( int curArea = 0; curArea < m_numAreas; curArea++ )
  {
    m_scaleAreas[curArea] = m_areas[curArea];
    m_scaleWeights[curArea] = (float) m_weights[curArea] / (float) ( m_areas[curArea].width * m_areas[curArea].height );
  }
}
void FeatureHistogram::generateRandomFeature(Size patchSize)
{

    initflag=false;
    //cua haar de scale weight
    Point2D position;
    Size baseDim;
    Size sizeFactor;
    int area;

    Size minSize = Size(3,3);
    int minArea = 9;

    bool valid = false;
    while (!valid)
    {
        //chosse position and scale
        position.row = rand()%(patchSize.height);
        position.col = rand()%(patchSize.width);

        baseDim.width = (int) ((1-sqrt(1-(float)rand()/RAND_MAX))*patchSize.width);
        baseDim.height = (int) ((1-sqrt(1-(float)rand()/RAND_MAX))*patchSize.height);

        //select types
        //float probType[11] = {0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0950f};
        float probType[11] = {0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
        float prob = (float)rand()/RAND_MAX;

        if (prob < probType[0])
        {
            //check if feature is valid
            sizeFactor.height = 2;
            sizeFactor.width = 1;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type1");
            m_numAreas = 2;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );

            valid = true;

        }
        else if (prob < probType[0]+probType[1])
        {
            //check if feature is valid
            sizeFactor.height = 1;
            sizeFactor.width = 2;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type2");
            m_numAreas = 2;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;

        }
        else if (prob < probType[0]+probType[1]+probType[2])
        {
            //check if feature is valid
            sizeFactor.height = 4;
            sizeFactor.width = 1;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type3");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -2;
            m_weights[2] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = 2*baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row+3*baseDim.height;
            m_areas[2].left = position.col;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3])
        {
            //check if feature is valid
            sizeFactor.height = 1;
            sizeFactor.width = 4;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type3");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -2;
            m_weights[2] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = 2*baseDim.width;
            m_areas[2].upper = position.row;
            m_areas[2].left = position.col+3*baseDim.width;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4])
        {
            //check if feature is valid
            sizeFactor.height = 2;
            sizeFactor.width = 2;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type5");
            m_numAreas = 4;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -1;
            m_weights[2] = -1;
            m_weights[3] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row+baseDim.height;
            m_areas[2].left = position.col;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_areas[3].upper = position.row+baseDim.height;
            m_areas[3].left = position.col+baseDim.width;
            m_areas[3].height = baseDim.height;
            m_areas[3].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5])
        {
            //check if feature is valid
            sizeFactor.height = 3;
            sizeFactor.width = 3;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type6");
            m_numAreas = 2;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -9;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = 3*baseDim.height;
            m_areas[0].width = 3*baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_initMean = -8*128;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob< probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6])
        {
            //check if feature is valid
            sizeFactor.height = 3;
            sizeFactor.width = 1;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type7");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -2;
            m_weights[2] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row+baseDim.height*2;
            m_areas[2].left = position.col;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7])
        {
            //check if feature is valid
            sizeFactor.height = 1;
            sizeFactor.width = 3;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;

            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;

            if (area < minArea)
                continue;

            strcpy (m_type, "Type8");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -2;
            m_weights[2] = 1;
            m_areas= new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row;
            m_areas[2].left = position.col+2*baseDim.width;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8])
        {
            //check if feature is valid
            sizeFactor.height = 3;
            sizeFactor.width = 3;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type9");
            m_numAreas = 2;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -2;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = 3*baseDim.height;
            m_areas[0].width = 3*baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_initMean = 0;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob< probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8]+probType[9])
        {
            //check if feature is valid
            sizeFactor.height = 3;
            sizeFactor.width = 1;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type10");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -1;
            m_weights[2] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col;
            m_areas[1].upper = position.row+baseDim.height;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row+baseDim.height*2;
            m_areas[2].left = position.col;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 128;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8]+probType[9]+probType[10])
        {
            //check if feature is valid
            sizeFactor.height = 1;
            sizeFactor.width = 3;
            if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
                    position.col + baseDim.width*sizeFactor.width >= patchSize.width)
                continue;
            area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
            if (area < minArea)
                continue;

            strcpy (m_type, "Type11");
            m_numAreas = 3;
            m_weights = new int[m_numAreas];
            m_weights[0] = 1;
            m_weights[1] = -1;
            m_weights[2] = 1;
            m_areas = new Rect[m_numAreas];
            m_areas[0].left = position.col;
            m_areas[0].upper = position.row;
            m_areas[0].height = baseDim.height;
            m_areas[0].width = baseDim.width;
            m_areas[1].left = position.col+baseDim.width;
            m_areas[1].upper = position.row;
            m_areas[1].height = baseDim.height;
            m_areas[1].width = baseDim.width;
            m_areas[2].upper = position.row;
            m_areas[2].left = position.col+2*baseDim.width;
            m_areas[2].height = baseDim.height;
            m_areas[2].width = baseDim.width;
            m_initMean = 128;
            m_initSigma = INITSIGMA( m_numAreas );
            valid = true;
        }
        else
            assert (false);
    }

    m_initSize = patchSize;
    m_curSize = m_initSize;
    m_scaleFactorWidth = m_scaleFactorHeight = 1.0f;
    m_scaleAreas = new Rect[m_numAreas];
    m_scaleWeights = new float[m_numAreas];
    for (int curArea = 0; curArea<m_numAreas; curArea++) {
        m_scaleAreas[curArea] = m_areas[curArea];
        m_scaleWeights[curArea] = (float)m_weights[curArea] /
                                  (float)(m_areas[curArea].width*m_areas[curArea].height);
    }
}