Exemplo n.º 1
0
/**
 * Example of a test. To be completed.
 *
 */
bool testDistanceTransformation()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;

  trace.beginBlock ( "Testing the whole DT computation" );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef HueShadeColorMap<unsigned char, 2> HueTwice;
  typedef GrayscaleColorMap<unsigned char> Gray;
  Point a ( 2, 2 );
  Point b ( 15, 15 );
  typedef ImageSelector<Domain, unsigned int>::Type Image;
  Image image ( a, b );

  for ( unsigned k = 0; k < 49; k++ )
  {
    a[0] = ( k / 7 ) + 5;
    a[1] = ( k % 7 ) + 5;
    image.setValue ( a, 128 );
  }



  DistanceTransformation<Image, 2> dt;
  typedef DistanceTransformation<Image, 2>::OutputImage ImageLong;

  dt.checkTypesValidity ( image );

  Board2D board;
  board.setUnit ( LibBoard::Board::UCentimeter );
  image.selfDraw<Gray> ( board, 0, 255 );
  board.saveSVG ( "image-preDT.svg" );
  //We just iterate on the Domain points and print out the point coordinates.
  std::copy ( image.begin(),
        image.end(),
        std::ostream_iterator<unsigned int> ( std::cout, " " ) );
  
  
  
  ImageLong result = dt.compute ( image );
  
  trace.warning() << result << endl;
  //We just iterate on the Domain points and print out the point coordinates.
  ImageLong::ConstIterator it = result.begin();
  for (unsigned int y = 2; y < 16; y++)
  {
    for (unsigned int x = 2; x < 16; x++)
    {
      std::cout << result(it) << " ";
      ++it;
    }
    std::cout << std::endl;
  }



  board.clear();
  result.selfDraw<Gray> ( board, 0, 16 );
  board.saveSVG ( "image-postDT.svg" );


  trace.info() << result << endl;

  trace.endBlock();

  return nbok == nb;
}
Exemplo n.º 2
0
/**
 * Example of a test. To be completed.
 *
 */
bool testDistanceTransformationBorder()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;

  trace.beginBlock ( "Testing DT computation with Infinity values at the first step" );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef HueShadeColorMap<DGtal::uint64_t, 2> Hue;
  typedef GrayscaleColorMap<DGtal::uint64_t> Gray;

  Point a (0, 0 );
  Point b ( 128, 128 );

  typedef ImageSelector<Domain, unsigned int>::Type Image;
  Image image ( a, b );

  for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
    image.setValue ( it, 128 );


  randomSeeds(image, 19, 0);

 
  DistanceTransformation<Image, 2> dt;
  typedef DistanceTransformation<Image, 2>::OutputImage ImageLong;

  dt.checkTypesValidity ( image );

  Board2D board;
  board.setUnit ( LibBoard::Board::UCentimeter );
  image.selfDraw<Hue> ( board, 0, 150 );
  board.saveSVG ( "image-preDT-border.svg" );


  ImageLong result = dt.compute ( image );

  DGtal::uint64_t maxv = 0;
  for ( ImageLong::Iterator it = result.begin(), itend = result.end();it != itend; ++it)
    if ( (*it) > maxv)
      maxv = (*it);

  ImageLong::ConstIterator it = result.begin();
  for (unsigned int y = 0; y < 33; y++)
  {
    for (unsigned int x = 0; x < 33; x++)
    {
      std::cout << std::setw(4) << result(it) << " ";
      ++it;
    }
    std::cout << std::endl;
  }

  trace.warning() << result << "MaxV = " << maxv << endl;


  board.clear();
  result.selfDraw<Hue> ( board, 0, maxv + 1);
  board.saveSVG ( "image-postDT-border.svg" );


  trace.info() << result << endl;

  trace.endBlock();

  return nbok == nb;
}
Exemplo n.º 3
0
/**
 * Example of a test. To be completed.
 *
 */
bool testDistanceTransformationNeg()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;

  trace.beginBlock ( "Testing the whole DT computation" );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef HueShadeColorMap<unsigned char, 2> HueTwice;
  typedef GrayscaleColorMap<unsigned char> Gray;
  Point a ( -10, -10 );
  Point b ( 10, 10 );
  typedef ImageSelector<Domain, unsigned int>::Type Image;
  Image image ( a, b );

  for(int y=-10; y<=10;y++) 
    for(int x=-10; x<=10;x++)
      {
  if ((abs(x)<7) && (abs(y)<5))
    image.setValue(Point(x,y),1);
  else
    image.setValue(Point(x,y),0);
      }
  
  DistanceTransformation<Image, 2> dt;
  typedef DistanceTransformation<Image, 2>::OutputImage ImageLong;

  dt.checkTypesValidity ( image );

  Board2D board;
  board.setUnit ( LibBoard::Board::UCentimeter );
  image.selfDraw<Gray> ( board, 0, 1 );
  board.saveSVG ( "image-preDT-neg.svg" );


  for(int y=-10; y<=10;y++) 
    {
      for(int x=-10; x<=10;x++)
  {
    std::cout<<image(Point(x,y))<<"  ";
  }
      std::cout<<std::endl;
    }
  

  ImageLong result = dt.compute ( image );
  
  DGtal::int64_t maxv=0;
  for(ImageLong::Iterator it = result.begin(), itend = result.end();
      it != itend ; ++it)
    if (result(it) > maxv)
      maxv = result(it);

  for(int y=-10; y<=10;y++) 
    {
      for(int x=-10; x<=10;x++)
  {
    std::cout<<result(Point(x,y))<<"  ";
  }
      std::cout<<std::endl;
    }
  


  trace.warning() << result << endl;

  board.clear();
  result.selfDraw<Gray> ( board, 0, maxv );
  board.saveSVG ( "image-postDT-neg.svg" );


  trace.info() << result << endl;

  trace.endBlock();

  return nbok == nb;
}
Exemplo n.º 4
0
bool testDTFromSet()
{
unsigned int nbok = 0;
  unsigned int nb = 0;

  trace.beginBlock ( "Testing the whole DT computation from a Set" );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef ImageSelector<Domain, unsigned int>::Type Image;
  typedef HueShadeColorMap<DGtal::uint64_t, 2> Hue;

  DistanceTransformation<Image, 2> dt;
  typedef DistanceTransformation<Image, 2>::OutputImage ImageLong;
  DistanceTransformation<Image, 0> dt0;
  typedef DistanceTransformation<Image, 0>::OutputImage ImageLong0;
  DistanceTransformation<Image, 1> dt1;
  typedef DistanceTransformation<Image, 1>::OutputImage ImageLong1;
  
  Board2D board;

  AccFlower2D<Z2i::Space> flower(Z2i::Point(0,0), 30, 5,2,0);
  Z2i::Domain domain(flower.getLowerBound(), flower.getUpperBound());
  Z2i::DigitalSet aSet(domain);
  
  Shapes<Z2i::Domain>::shaper(aSet, flower);

  ImageLong result = dt.compute ( aSet );
  ImageLong0 result0 = dt0.compute ( aSet );
  ImageLong1 result1 = dt1.compute ( aSet );
  
  trace.warning() << result << endl;
 
  DGtal::int64_t maxv = 0;
  for ( ImageLong::Iterator it = result.begin(), itend = result.end();
  it != itend; ++it)
    if ( (*it) > maxv)
      maxv = (*it);
  trace.error() << "MaxV="<<maxv<<std::endl;
  result.selfDraw<Hue> ( board, 0, maxv+1);
  board.saveSVG ( "image-DTSet.svg" );
  
  board.clear();
  maxv = 0;
  for ( ImageLong::Iterator it = result0.begin(), itend = result0.end();
  it != itend; ++it)
    if ( (*it) > maxv)
      maxv = (*it);
  trace.error() << "MaxV="<<maxv<<std::endl;
  result0.selfDraw<Hue> ( board, 0, maxv+1);
  board.saveSVG ( "image-DTSet-linfty.svg" );
  
  board.clear();
  maxv = 0;
  for ( ImageLong::Iterator it = result1.begin(), itend = result1.end();
  it != itend; ++it)
    if ( (*it) > maxv)
      maxv = (*it);
  trace.error() << "MaxV="<<maxv<<std::endl;
  result1.selfDraw<Hue> ( board, 0, maxv+1);
  board.saveSVG ( "image-DTSet-l1.svg" );
  trace.endBlock();

  return nbok == nb;
}
Exemplo n.º 5
0
/**
 * Example of a test. To be completed.
 *
 */
bool testDistanceTransformation()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;

  trace.beginBlock ( "Testing the whole DT computation" );

  typedef SpaceND<2> TSpace;
  typedef TSpace::Point Point;
  typedef HyperRectDomain<TSpace> Domain;
  typedef HueShadeColorMap<unsigned char, 2> HueTwice;
  typedef GrayscaleColorMap<unsigned char> Gray;
  Point a ( 2, 2 );
  Point b ( 15, 15 );
  typedef ImageSelector<Domain, unsigned int>::Type Image;
  Image image ( Domain(a, b ));

  for ( unsigned k = 0; k < 49; k++ )
    {
      a[0] = ( k / 7 ) + 5;
      a[1] = ( k % 7 ) + 5;
      image.setValue ( a, 128 );
    }
  a= Point(2,2);

  typedef SimpleThresholdForegroundPredicate<Image> Predicate;
  Predicate aPredicate(image,0);

  DistanceTransformation<TSpace, Predicate , 2> dt(Domain(a,b),aPredicate);
  typedef DistanceTransformation<TSpace, Predicate, 2>::OutputImage ImageLong;
  
  dt.checkTypesValidity ( );
  
  Board2D board;
  board.setUnit ( LibBoard::Board::UCentimeter );
  Display2DFactory::drawImage<Gray>(board, image, (unsigned int)0, (unsigned int)255);
  board.saveSVG ( "image-preDT.svg" );
  //We just iterate on the Domain points and print out the point coordinates.
  std::copy ( image.begin(),
	      image.end(),
	      std::ostream_iterator<unsigned int> ( std::cout, " " ) );
  
  
  
  ImageLong result = dt.compute (  );
  
  trace.warning() << result << endl;
  //We just iterate on the Domain points and print out the point coordinates.
  ImageLong::ConstIterator it = result.begin();
  ImageLong::ConstIterator itend = result.end();
  for (; it != itend; ++it)
    {
      std::cout << (*it) << " ";
    }
  std::cout << std::endl;

  board.clear();
  Display2DFactory::drawImage<Gray>(board, result, (DGtal::int64_t)0, (DGtal::int64_t)16);
  board.saveSVG ( "image-postDT.svg" );


  trace.info() << result << endl;

  trace.endBlock();

  return nbok == nb;
}