예제 #1
0
int main()
{
    const std::string examplesPath= "/home/remi/pred/DGtal_PRED/Source/Experience/";
    std::string filename =  examplesPath + "samples/contourS.pgm";
    Image image = DGtal::PNMReader<Image>::importPGM(filename);
    DGtal::trace.info() << "Imported image: "<<image<<endl;


    DGtal::Board2D aBoard;
    aBoard << image.domain();
    aBoard.saveSVG("imageDomainTuto.svg");
    aBoard.clear();
    Display2DFactory::drawImage<Gray>(aBoard, image, (unsigned char)0, (unsigned char)255);
    aBoard.saveEPS("imageDomainTuto2.eps");


    typedef IntervalForegroundPredicate<Image> Binarizer;
    Binarizer b(image,1, 135);
    typedef DGtal::DistanceTransformation<Z2i::Space, Binarizer, 2> DTL2;
    typedef DTL2::OutputImage OutputImage;
    DTL2 dt(image.domain(),b);

    OutputImage result = dt.compute();

    OutputImage::Value maxDT = (*std::max_element(result.begin(),
                                result.end()));
    typedef DGtal::HueShadeColorMap<OutputImage::Value,2> HueTwice;

    aBoard.clear();
    Display2DFactory::drawImage<HueTwice>(aBoard, result, (OutputImage::Value)0, (OutputImage::Value)maxDT);
    aBoard.saveEPS("imageDomainTuto3.eps");
}
예제 #2
0
void distanceTransformation() {
  
  /** Read a file **/
  typedef DGtal::ImageContainerBySTLVector< DGtal::Z2i::Domain, unsigned char> Image;
  typedef DGtal::GrayscaleColorMap<unsigned char> Gray;
  std::string filename =  examplesPath + "contourS.pgm";
  Image image = DGtal::PGMReader<Image>::importPGM(filename); 
  DGtal::trace.info() << "Imported image: "<<image<<std::endl;
  

  /** Saving domain and image **/
  DGtal::Board2D aBoard;
  aBoard << image.domain();  
  aBoard.saveSVG("imageDomainTuto.svg");
  aBoard.clear();
  DGtal::Display2DFactory::drawImage<Gray>(aBoard, image, (unsigned char)0, (unsigned char)255);
  aBoard.saveEPS("imageDomainTuto2.eps");

  /** Creating binarization and euclidean DT **/
  typedef DGtal::functors::IntervalForegroundPredicate<Image> Binarizer;
  //Threshold to 135
  Binarizer b(image,1, 135); 
  typedef DGtal::DistanceTransformation<DGtal::Z2i::Space, Binarizer, DGtal::Z2i::L2Metric> DTL2;
  DTL2 dt(&image.domain(),&b, &DGtal::Z2i::l2Metric );

  DTL2::Value maxDT = (*std::max_element(dt.constRange().begin(), 
                                         dt.constRange().end()));
  typedef DGtal::HueShadeColorMap<DTL2::Value,2> HueTwice;
  aBoard.clear();
  DGtal::Display2DFactory::drawImage<HueTwice>(aBoard, dt, (DTL2::Value)0, 
					       (DTL2::Value)maxDT);
  aBoard.saveEPS("imageDomainTuto3.eps");

}
예제 #3
0
파일: main.cpp 프로젝트: SqLL/DGtal_PRED
int main(int argc, char** argv)
{

if(argc != 4)
{
	cout << argc << endl;
	cout << "to use this program you have to enter this command line ./main path/of/the/picture connexity threshold " << endl;
	cout << "Threshold should be in 0-255" << endl;
	cout << "connexity should be 4connexity or 8connexity or chamfer5711" << endl;
}
else 
{
	int threshold = atoi(argv[2]);

	if(threshold <= 255 && threshold >= 0 && ( (strcmp(argv[3],"4connexity") == 0 ) || (strcmp(argv[3],"8connexity") == 0 ) || strcmp(argv[3],"chamfer5711") == 0) )
	{
		vector<point2dWeighting> myWeightingVector;

	   if(strcmp(argv[3],"4connexity") == 0 )
	   {
		   make4Connexity(myWeightingVector);
	   }
	   else if(strcmp(argv[3],"8connexity") == 0)
	   {
		   make8Connexity(myWeightingVector);
	   }
	   else
	   {
		   makeSimpleChamfrein(myWeightingVector);
	   }


      // mask creation
      SymmetricMask<point2dWeighting> myMask;
      SymmetricMaskGenerator<point2dWeighting> generateur;
      myMask = generateur.generateMask(myWeightingVector);



      // CMETRIC and distance Transform instanciation
      CChamferMetric<int,point2d> myMetric(myMask);
      ChamferDistanceTransform<int,point2d> myDistance(myMetric);



      Image image = DGtal::PNMReader<Image>::importPGM(argv[1], true); 


      /** distance transformation **/
      ImageInt output = myDistance.applyAlgorithm(image,threshold,true);


      /** output colorisation **/
      DGtal::Board2D aBoard;
      ImageInt::Value maxDT = (*std::max_element(output.begin(), 
                                                      output.end()));
      typedef DGtal::HueShadeColorMap<ImageInt::Value,2> HueTwice;
      aBoard.clear();
      Display2DFactory::drawImage<HueTwice>(aBoard, output, (ImageInt::Value)0, (ImageInt::Value)maxDT);
      aBoard.saveEPS(outputNameFile);

      /** distance transformation numeric output **/
      /*
      typename Image::Domain::ConstIterator dit= image.domain().begin();	
      for(;dit != image.domain().end();++dit)
      {
		      cout << (*dit) << " : " << (int)output(*dit) << endl;			
      }*/
	}
}
return 0;
}
int main()
{
  //shape
  typedef Flower2D<Z2i::Space> Flower; 
  Flower2D<Z2i::Space> flower(Z2i::Point(0,0), 20, 5, 5, 0);
  
  //! [shapeGridCurveEstimator-dig]
  //implicit digitization of a shape of type Flower 
  //into a digital space of type Space
  double h = 1; 
  GaussDigitizer<Z2i::Space,Flower> dig;  
  dig.attach( flower );
  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
            flower.getUpperBound()+Z2i::Vector(1,1), h ); 
  //! [shapeGridCurveEstimator-dig]
  
  //! [shapeGridCurveEstimator-prepareTracking]
  //Khalimsky space
  Z2i::KSpace ks;
  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
  //adjacency (4-connectivity)
  SurfelAdjacency<2> sAdj( true );
  //! [shapeGridCurveEstimator-prepareTracking]

  //! [shapeGridCurveEstimator-tracking]
  //searching for one boundary element
  Z2i::SCell bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 1000 );
  //tracking
  vector<Z2i::Point> boundaryPoints;
  Surfaces<Z2i::KSpace>
    ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
  //! [shapeGridCurveEstimator-tracking]

  //! [shapeGridCurveEstimator-instantiation]
  Z2i::Curve c;
  c.initFromVector( boundaryPoints );  
  //! [shapeGridCurveEstimator-instantiation]
  
  DGtal::Board2D aBoard;
  aBoard << c; 
  aBoard.saveEPS("DisplayGridCurve1.eps");  
  
  //! [shapeGridCurveEstimator-getRange]
  //range of points
  typedef Z2i::Curve::PointsRange Range; 
  Range r = c.getPointsRange(); 
  //! [shapeGridCurveEstimator-getRange]
  
  //! [shapeGridCurveEstimator-lengthEstimation]
  //length estimation
  DSSLengthEstimator< Range::ConstIterator > DSSlength;
  DSSlength.init( h, r.begin(), r.end(), c.isClosed() );
  double length1 = DSSlength.eval();
  trace.info() << "Length (h=" << h << "): " << length1 << endl; 
  //! [shapeGridCurveEstimator-lengthEstimation]

//@TODO correct init method of trueLengthEstimator (remove &flower)
  //! [shapeGridCurveEstimator-trueLengthEstimation]
  typedef ParametricShapeArcLengthFunctor< Flower > Length;
  TrueGlobalEstimatorOnPoints< 
    Range::ConstIterator, 
    Flower, 
    Length  >  trueLengthEstimator;
  trueLengthEstimator.init( h, r.begin(), r.end(), &flower, c.isClosed());
  double trueLength = trueLengthEstimator.eval(); 
  trace.info() << "ground truth: " << trueLength << endl; 
  //! [shapeGridCurveEstimator-trueLengthEstimation]

  //! [shapeGridCurveEstimator-higher]
  //implicit digitization at higher resolution
  h = 0.1; 
  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
            flower.getUpperBound()+Z2i::Vector(1,1), h ); 
  //a greater domain is needed in the Khalimsky space
  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
  //searching for one boundary element
  bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 10000 );
  //tracking
  Surfaces<Z2i::KSpace>
    ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
  //reset grid curve and its points range
  c.initFromVector( boundaryPoints );
  Range r2 = c.getPointsRange(); 
  //estimate length
  DSSlength.init( h, r2.begin(), r2.end(), c.isClosed() );
  double length2 = DSSlength.eval();
  trace.info() << "Length (h=" << h << "): " << length2 << endl;  
  //! [shapeGridCurveEstimator-higher]
  
  aBoard.clear(); 
  aBoard << c; 
  aBoard.saveEPS("DisplayGridCurve01.eps");  
  
  return 0;

}