image::ArrayGrid<bool>* PyramidKeyPointDetector::FindLocalMaxima( ArrayGrid<double>* pGrid )
{
   int size = 5;
   int width   = pGrid->GetWidth();
   int height  = pGrid->GetHeight();
   bool needsInitialisation = true;
   double initialValue = false;
   ArrayGrid<bool>* pKeyPointsMap = new ArrayGrid<bool>( width, height, needsInitialisation, initialValue );
   pKeyPointsMap->SetGridValues( false );
   for (int y = size; y < height-size; y++)
   {
      for (int x = size; x < width-size; x++)
      {
         bool isLocalMaximum = true;
         for (int dy = -size; dy <= size; dy++)
         {
            for (int dx = -size; dx <= size; dx++)
            {
               if (  (dx != 0) || (dy != 0) )
               {
                  if (pGrid->GetValue(x+dx, y+dy) >= pGrid->GetValue(x, y))
                  {
                     isLocalMaximum = false;
                  }
               }
            }
         }
         pKeyPointsMap->SetValue(x, y, isLocalMaximum);
      }
   }
   return pKeyPointsMap;
}
Example #2
0
ArrayGrid<bool>* StegerLineDetector::Run( ArrayGrid<double>* pGridIn, double sigmaSmooth, double lowerThreshold, double higherThreshold, bool isModeLight )
{
   int width = pGridIn->GetWidth();
   int height = pGridIn->GetHeight();
   OrientationGrid* pOrientationGrid = new OrientationGrid(width, height);  // NOT initialized at construction; values are set below
   ArrayGrid<bool>* pLineGrid = new ArrayGrid<bool>(width, height);  // NOT initialized at construction; values are set below
   pLineGrid->SetGridValues( false );
   
   ArrayGrid<double>* pGx  = GaussConvolve::DerivativeConvolveFFT( pGridIn, sigmaSmooth, sigmaSmooth, GaussConvolve::DERIVATIVE_X  );
   ArrayGrid<double>* pGy  = GaussConvolve::DerivativeConvolveFFT( pGridIn, sigmaSmooth, sigmaSmooth, GaussConvolve::DERIVATIVE_Y  );
   ArrayGrid<double>* pGxx = GaussConvolve::DerivativeConvolveFFT( pGridIn, sigmaSmooth, sigmaSmooth, GaussConvolve::DERIVATIVE_XX );
   ArrayGrid<double>* pGyy = GaussConvolve::DerivativeConvolveFFT( pGridIn, sigmaSmooth, sigmaSmooth, GaussConvolve::DERIVATIVE_YY );
   ArrayGrid<double>* pGxy = GaussConvolve::DerivativeConvolveFFT( pGridIn, sigmaSmooth, sigmaSmooth, GaussConvolve::DERIVATIVE_XY );
   
   for (int y = 0; y < height; y++)
   {
      for (int x = 0; x < width; x++)
      {
         double eigenValue1, eigenValue2, eigenValue;
         common::Point<double> eigenVector1;
         common::Point<double> eigenVector2;
         
         EigenValueComputation( pGxx->GetValue(x, y), pGyy->GetValue(x, y), pGxy->GetValue(x, y),
                                eigenValue1, eigenValue2, eigenVector1, eigenVector2);

         if (isModeLight == true)
         {
            eigenValue = -eigenValue1;
         }
         else
         {
            eigenValue = eigenValue1;
         }
         
         if (eigenValue > 0.0)
         {
            double n1 = eigenVector1.x;
            double n2 = eigenVector1.y;
            
            double a = pGxx->GetValue(x, y) * n1 * n1 + 2.0 * pGxy->GetValue(x, y) * n1 * n2 + pGyy->GetValue(x, y) * n2 * n2;
            double b = pGx->GetValue(x, y) * n1 + pGy->GetValue(x, y) * n2;
            double linearSolution;
            if ( MathUtils::SolveLinearEquation( a, b, linearSolution ) == true )
            {
               double p1 = linearSolution * n1;
               double p2 = linearSolution * n2;
               if ((fabs (p1) <= EDGE_THRESHOLD) && (fabs (p2) <= EDGE_THRESHOLD))
               {
                  int xx = (int)(x + p1 + 0.5);
                  int yy = (int)(y + p2 + 0.5);
                  if (  (xx >= 0) && (xx < width) && (yy >=0) && (yy < height))
                  {
                     if (eigenValue >= lowerThreshold)
                     {
                        if (eigenValue >= higherThreshold)
                        {
                           pLineGrid->SetValue(xx, yy, true);
                        }
                     }
                     else
                     {
                        pLineGrid->SetValue(xx, yy, false);
                     }
                  }
               }
            }
            
            pOrientationGrid->SetAngle( x, y, MathUtils::ComputeArgument( eigenVector1.x,  eigenVector1.y ) );
            pOrientationGrid->SetMagnitude( x, y, eigenValue1);
         }
      }
   }
   //pOrientationGrid->ExportMagnitudeImage( string("StegerMagnitude.pgm") );
   //pOrientationGrid->ExportOrientationImage( string("StegerOrientation.pgm"), -100000.0 );
   
   delete pGx;
   delete pGy;
   delete pGxx;
   delete pGyy;
   delete pGxy;
   delete pOrientationGrid;
   return pLineGrid;
}