コード例 #1
0
/**
 * Example of a test. To be completed.
 *
 */
bool testBinomialConvolver()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing block ..." );
  typedef PointVector<2, double> RealPoint;
  std::vector< RealPoint > points;
#ifdef CPP11_INITIALIZER_LIST
  points.push_back( RealPoint( { 0.0, 0.0 } ) ); 
  points.push_back( RealPoint( { 1.0, 0.0 } ) ); 
  points.push_back( RealPoint( { 2.0, 0.0 } ) ); 
  points.push_back( RealPoint( { 2.0, 1.0 } ) ); 
  points.push_back( RealPoint( { 2.0, 2.0 } ) ); 
  points.push_back( RealPoint( { 1.0, 2.0 } ) ); 
  points.push_back( RealPoint( { 0.0, 2.0 } ) ); 
  points.push_back( RealPoint( { 0.0, 1.0 } ) ); 
#else
   points.push_back( RealPoint(  0.0, 0.0  ) ); 
  points.push_back( RealPoint(  1.0, 0.0  ) ); 
  points.push_back( RealPoint(  2.0, 0.0  ) ); 
  points.push_back( RealPoint(  2.0, 1.0  ) ); 
  points.push_back( RealPoint( 2.0, 2.0  ) ); 
  points.push_back( RealPoint( 1.0, 2.0  ) ); 
  points.push_back( RealPoint(  0.0, 2.0  ) ); 
  points.push_back( RealPoint(  0.0, 1.0  ) ); 
#endif
  
  typedef std::vector< RealPoint >::const_iterator ConstIteratorOnPoints;
  typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
  
  for ( unsigned int n = 1; n < 10; ++n )
    {
      trace.info() << "Binomial convolver n=" << n << std::endl;
      MyBinomialConvolver bcc( n );
      bcc.init( 1.0, points.begin(), points.end(), true );
      for ( unsigned int i = 0; i < 8; ++i )
        std::cout << i
            << " " << bcc.x( i ).first
            << " " << bcc.x( i ).second
            << " " << bcc.tangent( i ).first
            << " " << bcc.tangent( i ).second
            << " " << bcc.curvature( i )
            << std::endl;
    }
  unsigned int n = MyBinomialConvolver::suggestedSize( 1.0, points.begin(), points.end() );
  trace.info() << "Binomial convolver suggested n=" 
         << n
         << std::endl;

  typedef TangentFromBinomialConvolverFunctor< MyBinomialConvolver, RealPoint >
    TangentBCFct;
  typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double >
    CurvatureBCFct;
  BinomialConvolverEstimator< MyBinomialConvolver, TangentBCFct> tgtEstimator;
  BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> curvEstimator;
  tgtEstimator.init( 1.0, points.begin(), points.end(), true );
  curvEstimator.init( 1.0, points.begin(), points.end(), true );
  for ( ConstIteratorOnPoints it = points.begin(), it_end = points.end();
  it != it_end; ++it )
    {
      std::cout << *it 
    << " " << tgtEstimator.eval( it ) 
    << " " << curvEstimator.eval( it ) 
    << std::endl;
    }
  nbok += true ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
         << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}
コード例 #2
0
ファイル: tangentBC.cpp プロジェクト: malaterre/DGtal
int main( int argc, char** argv )
{
  // parse command line ----------------------------------------------
  po::options_description general_opt("Allowed options are: ");
  general_opt.add_options()
    ("help,h", "display this message")
    ("FreemanChain,f", po::value<std::string>(), "FreemanChain file name")
    ("GridStep,step", po::value<double>()->default_value(1.0), "Grid step");
  
  
  
  po::variables_map vm;
  po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  po::notify(vm);    
  if(vm.count("help")||argc<=1 || (not(vm.count("FreemanChain"))) )
    {
      trace.info()<< "Tangent using a binomial convolver " <<std::endl << "Basic usage: "<<std::endl
		  << "\t tangentBC [options] --FreemanChain  <fileName> "<<std::endl
		  << general_opt << "\n"
		  << "NB: the file may contain several freeman chains." << "\n";
      return 0;
    }
  
  
  double h = vm["GridStep"].as<double>();  


 
  if(vm.count("FreemanChain")){
    string fileName = vm["FreemanChain"].as<string>();

    typedef Z2i::Space Space; 
    typedef Space::Point Point; 
    typedef RealPointVector<2> RealPoint; 
    typedef Space::Integer Integer;  
    typedef FreemanChain<Integer> FreemanChain; 
    typedef vector< Point > Storage;
    typedef Storage::const_iterator ConstIteratorOnPoints; 

    vector< FreemanChain > vectFcs =  
      PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName); 

    for(unsigned int i=0; i<vectFcs.size(); i++){

      bool isClosed = vectFcs.at(i).isClosed(); 
      cout << "# grid curve " << i << "/" << vectFcs.size() << " "
      << ( (isClosed)?"closed":"open" ) << endl;

      Storage vectPts; 
      FreemanChain::getContourPoints( vectFcs.at(i), vectPts ); 

      // Binomial
      std::cout << "# Curvature estimation from binomial convolution" << std::endl;
      typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
      std::cout << "# mask size = " << 
      MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
      typedef 
	TangentFromBinomialConvolverFunctor< MyBinomialConvolver, RealPoint >
	TangentBCFct;
      BinomialConvolverEstimator< MyBinomialConvolver, TangentBCFct> 
	BCTangentEstimator;

      BCTangentEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );

      vector<RealPoint> tangents( vectPts.size() ); 
      BCTangentEstimator.eval( vectPts.begin(), vectPts.end(), 
			       tangents.begin() ); 

      // Output
      cout << "# id tangent.x tangent.y angle(atan2(y,x))" << endl;  
      unsigned int j = 0;
      for ( ConstIteratorOnPoints 
	      it = vectPts.begin(), it_end = vectPts.end();
	    it != it_end; ++it, ++j ) 
	{
	  double x = tangents[ j ][ 0 ];
	  double y = tangents[ j ][ 1 ];
	  cout << j << setprecision( 15 )
	       << " " << x << " " << y 
	       << " " << atan2( y, x )
	       << endl;
	}

    }

  }
  return 0;
}
コード例 #3
0
ファイル: curvatureBC.cpp プロジェクト: SqLL/DGtalTools
int main( int argc, char** argv )
{
  // parse command line ----------------------------------------------
  po::options_description general_opt("Allowed options are: ");
  general_opt.add_options()
    ("help,h", "display this message")
    ("FreemanChain,f", po::value<std::string>(), "FreemanChain file name")
    ("GridStep,step", po::value<double>()->default_value(1.0), "Grid step");
  
  
  bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify(vm);    
  if(!parseOK || vm.count("help")||argc<=1 || (!(vm.count("FreemanChain"))) )
    {
      trace.info()<< "Curvature using a binomial convolver " <<std::endl << "Basic usage: "<<std::endl
      << "\t curvatureBC [options] --FreemanChain  <fileName> "<<std::endl
      << general_opt << "\n";
      return 0;
    }
  
  
  double h = vm["GridStep"].as<double>();  


 
  if(vm.count("FreemanChain")){
    string fileName = vm["FreemanChain"].as<string>();

    typedef Z2i::Space Space; 
    typedef Space::Point Point; 
    typedef Space::Integer Integer;  
    typedef FreemanChain<Integer> FreemanChain; 
    typedef vector< Point > Storage;
    typedef Storage::const_iterator ConstIteratorOnPoints; 

    vector< FreemanChain > vectFcs =  PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName); 
   

    for(unsigned int i=0; i<vectFcs.size(); i++){

      bool isClosed = vectFcs.at(i).isClosed(); 
      cout << "# grid curve " << i+1 << "/" << vectFcs.size() << " "
      << ( (isClosed)?"closed":"open" ) << endl;

      Storage vectPts; 
      FreemanChain::getContourPoints( vectFcs.at(i), vectPts ); 

      // Binomial
      std::cout << "# Curvature estimation from binomial convolution" << std::endl;
      typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
      std::cout << "# mask size = " << 
      MyBinomialConvolver::suggestedSize( h, vectPts.begin(), vectPts.end() ) << std::endl;
      typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double >
      CurvatureBCFct;
      BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;

      BCCurvatureEstimator.init( h, vectPts.begin(), vectPts.end(), isClosed );

      vector <double> curvatures( vectPts.size() ); 
      BCCurvatureEstimator.eval( vectPts.begin(), vectPts.end(), curvatures.begin() ); 

      // Output
      cout << "# id curvature" << endl;  
      unsigned int j = 0;
      for ( ConstIteratorOnPoints it = vectPts.begin(), it_end = vectPts.end();
      it != it_end; ++it, ++j ) {
  cout << j << setprecision( 15 )
       << " " << curvatures[ j ] << endl;
      }

   }

 }
 
  return 0;
}