DGtal  0.9.3
Functions
testDistanceTransformation.cpp File Reference
#include <iostream>
#include <iomanip>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/geometry/volumes/distance/VoronoiMap.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
Include dependency graph for testDistanceTransformation.cpp:

Go to the source code of this file.

Functions

template<typename Image >
void randomSeeds (Image &input, const unsigned int nb, const int value)
 
bool testDistanceTransformation ()
 
bool testDistanceTransformationNeg ()
 
bool testDTFromSet ()
 
bool testDistanceTransformationBorder ()
 
bool testDistanceTransformation3D ()
 
bool testChessboard ()
 
template<typename Space , int norm>
bool testCompareExactInexact (unsigned int size, unsigned int nb)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/09/30

Functions for testing class DistanceTransformation.

This file is part of the DGtal library.

Definition in file testDistanceTransformation.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 628 of file testDistanceTransformation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testChessboard(), testDistanceTransformation(), testDistanceTransformation3D(), testDistanceTransformationBorder(), testDistanceTransformationNeg(), testDTFromSet(), and DGtal::trace.

628  {
629 
630  trace.beginBlock ( "Testing class DistanceTransformation" );
631  trace.info() << "Args:";
632  for ( int i = 0; i < argc; ++i )
633  trace.info() << " " << argv[ i ];
634  trace.info() << endl;
635 
637  && testDTFromSet()
640  && testChessboard()
641  && testDTFromSet()
642  && testCompareExactInexact<Z2i::Space, 2>(50, 50)
643  && testCompareExactInexact<Z3i::Space, 2>(50, 50)
644  && testCompareExactInexact<Z2i::Space, 4>(50, 50)
645  && testCompareExactInexact<Z3i::Space, 4>(50, 50)
646  ;
647  //&& ... other tests
648  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
649  trace.endBlock();
650  return res ? 0 : 1;
651 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool testDistanceTransformation3D()
double endBlock()
bool testDistanceTransformation()
std::ostream & emphase()
bool testChessboard()
bool testDistanceTransformationBorder()
std::ostream & info()
bool testDTFromSet()
bool testDistanceTransformationNeg()

◆ randomSeeds()

template<typename Image >
void randomSeeds ( Image input,
const unsigned int  nb,
const int  value 
)
Examples:
geometry/volumes/distance/distancetransform2D.cpp, and geometry/volumes/distance/distancetransform3D.cpp.

Definition at line 60 of file testDistanceTransformation.cpp.

References dim(), DGtal::Image< TImageContainer >::domain(), and DGtal::Image< TImageContainer >::setValue().

Referenced by testChessboard(), and testDistanceTransformationBorder().

61 {
62  typename Image::Point p, low = input.domain().lowerBound(), up = input.domain().upperBound();
63  typename Image::Vector ext;
64 
65  for (Dimension i = 0; i < Image::Domain::dimension; i++)
66  ext[i] = up[i] - low[i] + 1;
67 
68 
69  for (unsigned int k = 0 ; k < nb; k++)
70  {
71  for (unsigned int dim = 0; dim < Image::dimension; dim++)
72  {
73  p[dim] = rand() % (ext[dim]) + low[dim];
74  }
75  input.setValue(p, value);
76  }
77 }
DGtal::uint32_t Dimension
Definition: Common.h:120
void setValue(const Point &aPoint, const Value &aValue)
Definition: Image.h:247
unsigned int dim(const Vector &z)
const Domain & domain() const
Definition: Image.h:192

◆ testChessboard()

bool testChessboard ( )

Definition at line 468 of file testDistanceTransformation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), randomSeeds(), LibBoard::Board::setUnit(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

Referenced by main().

469 {
470  unsigned int nbok = 0;
471  unsigned int nb = 0;
472 
473  trace.beginBlock ( "Testing DT computation with Infinity values at the first step" );
474 
475  typedef SpaceND<2> TSpace;
476  typedef TSpace::Point Point;
479 
480  Point a (0, 0 );
481  Point b ( 128, 128 );
482  Domain dom(a,b);
483 
485  Image image ( dom );
486 
487  for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
488  (*it) = 128;
489 
490 
491  randomSeeds(image, 19, 0);
492 
494  Predicate aPredicate(image,0);
495 
496 
497  // L_euc metric
499  L2Metric l2;
501  DT2 dt2(&dom, &aPredicate, &l2);
502  DT2 dt2_periodic( &dom, &aPredicate, &l2, {true, true} );
503 
504  //L_infinity metric
505  //typedef DistanceTransformation<TSpace,Predicate, 0> DT;
506  //DT dt(Domain(a,b), aPredicate);;
507 
508  //L_1 metric
510  L1Metric l1;
512  DT1 dt1(&dom,&aPredicate,&l1);
513  DT1 dt1_periodic( &dom, &aPredicate, &l1, {true, true} );
514 
515  DGtal::int64_t maxv = 0;
516  for ( DistanceTransformation<TSpace,Predicate, L2Metric>::ConstRange::ConstIterator it = dt2.constRange().begin(), itend = dt2.constRange().end();it != itend; ++it)
517  if ( (*it) > maxv)
518  maxv = (*it);
519 
520  trace.warning() << dt2 << "MaxV = " << maxv << endl;
521  //We display the values on a 2D slice
522  for (unsigned int y = 0; y < 16; y++)
523  {
524  for (unsigned int x = 0; x < 16; x++)
525  {
526  Point p(x, y);
527  std::cout << std::setw(4) << dt2(p) << " ";
528  }
529  std::cout << std::endl;
530  }
531 
532  trace.info()<< "Exporting to SVG"<<endl;
533 
534  Board2D board;
536  Display2DFactory::drawImage<Hue>(board, dt2, (DGtal::int64_t)0, (DGtal::int64_t)maxv+1);
537  board.saveSVG ( "image-DT-l2.svg" );
538 
539  board.clear();
540  Display2DFactory::drawImage<Hue>(board, dt2_periodic, (DGtal::int64_t)0, (DGtal::int64_t)maxv+1);
541  board.saveSVG ( "image-DT-l2-periodic.svg" );
542 
543  trace.info()<< "done"<<endl;
544 
545 
546 
547  trace.info()<< "max L1"<<endl;
548  maxv = 0;
550  itend = dt1.constRange().end();
551  it2 != itend; ++it2)
552  {
553  if ( *it2 > maxv)
554  maxv = (*it2);
555  }
556 
557  trace.info()<< "Exporting to SVG L1"<<endl;
558  board.clear();
559  Display2DFactory::drawImage<Hue>(board, dt1, (DGtal::int64_t)0, (DGtal::int64_t)maxv+1);
560  board.saveSVG ( "image-DT-l1.svg" );
561 
562  board.clear();
563  Display2DFactory::drawImage<Hue>(board, dt1_periodic, (DGtal::int64_t)0, (DGtal::int64_t)maxv+1);
564  board.saveSVG ( "image-DT-l1-periodic.svg" );
565 
566  trace.info()<< "done"<<endl;
567 
568 
569  trace.endBlock();
570 
571  return nbok == nb;
572 }
void beginBlock(const std::string &keyword="")
ExactPredicateLpSeparableMetric< Space, 1 > L1Metric
Definition: StdDefs.h:119
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements separable l_p metrics with exact predicates.
void randomSeeds(Image &input, const unsigned int nb, const int value)
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
void setUnit(Unit unit)
Definition: Board.cpp:240
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Image image(domain)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testCompareExactInexact()

template<typename Space , int norm>
bool testCompareExactInexact ( unsigned int  size,
unsigned int  nb 
)

Definition at line 575 of file testDistanceTransformation.cpp.

References DGtal::Trace::beginBlock(), dim(), DGtal::SpaceND< dim, TInteger >::dimension, domain(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

576 {
577  trace.beginBlock("Checking Exact/Inexct predicate metrics");
579  typedef InexactPredicateLpSeparableMetric<Space> MetricInex;
581  typedef typename Space::Point Point;
582  typedef DigitalSetBySTLSet<Domain> Set;
583  // typedef NotPointPredicate<SetPredicate<Set> > NegPredicate;
584  typedef functors::NotPointPredicate<Set> NegPredicate;
585 
586  Point low=Point::diagonal(0),
587  up=Point::diagonal(size);
588 
589  Domain domain(low,up);
590  Set set(domain);
591 
592  for(unsigned int i = 0; i<nb; ++i)
593  {
594  Point p;
595  for(unsigned int dim=0; dim<Space::dimension;++dim)
596  p[dim] = rand() % size;
597  set.insert(p);
598  }
599 
600  trace.info()<< "Testing metrics "<<MetricEx()<<" "<<MetricInex(norm)<<std::endl;
601  trace.info()<< "Testing space dimension "<<Space::dimension<<std::endl;
602  trace.info()<< "Inserting "<<set.size() << " points."<<std::endl;
603 
604  // SetPredicate<Set> setPred(set);
605  NegPredicate negPred(set);
606 
609  MetricEx metricEx;
610  MetricInex metricInex(norm);
611  DTEx dtex(&domain, &negPred, &metricEx);
612  DTIn dtinex(&domain, &negPred, &metricInex);
613 
614  double MSE=0.0;
615  typename DTEx::ConstRange::ConstIterator it=dtex.constRange().begin(), itend=dtex.constRange().end();
616  typename DTIn::ConstRange::ConstIterator it2 = dtinex.constRange().begin();
617  for( ; it != itend; ++it, ++it2)
618  MSE += ((*it) - (*it2))*((*it) - (*it2));
619 
620  trace.warning()<<"Resulting MSE= "<<MSE;
621  trace.endBlock();
622  return true;
623 }
void beginBlock(const std::string &keyword="")
Aim: The predicate returns true when the point predicate given at construction return false...
static const Dimension dimension
static constants to store the dimension.
Definition: SpaceND.h:132
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
Aim: implements separable l_p metrics with approximated predicates.
double endBlock()
Aim: implements separable l_p metrics with exact predicates.
MyPointD Point
Definition: testClone2.cpp:383
unsigned int dim(const Vector &z)
std::ostream & warning()
std::ostream & info()
Aim: A container class for storing sets of digital points within some given domain.

◆ testDistanceTransformation()

bool testDistanceTransformation ( )

Example of a test. To be completed.

Definition at line 85 of file testDistanceTransformation.cpp.

References DGtal::DefaultConstImageRange< TImage >::begin(), DGtal::Trace::beginBlock(), DGtal::DistanceTransformation< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::constRange(), DGtal::DefaultConstImageRange< TImage >::end(), DGtal::Trace::endBlock(), DGtal::DistanceTransformation< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::getVoronoiVector(), image(), DGtal::Trace::info(), LibBoard::Board::setUnit(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

Referenced by main().

86 {
87  bool allfine;
88 
89  trace.beginBlock ( "Testing the whole DT computation" );
90 
91  typedef SpaceND<2> TSpace;
92  typedef TSpace::Point Point;
95  Point a ( 2, 2 );
96  Point b ( 15, 15 );
98  Image image ( Domain(a, b ));
99 
100  for ( unsigned k = 0; k < 49; k++ )
101  {
102  a[0] = ( k / 7 ) + 5;
103  a[1] = ( k % 7 ) + 5;
104  image.setValue ( a, 128 );
105  }
106  a= Point(2,2);
107 
109  Predicate aPredicate(image,0);
110 
112  L2Metric l2;
113  Domain dom(a,b);
115  VoronoiMap<Z2i::Space, Predicate, L2Metric> voro(&dom,&aPredicate,&l2);
116 
117  Board2D board;
119  Display2DFactory::drawImage<Gray>(board, image, (unsigned int)0, (unsigned int)255);
120  board.saveSVG ( "image-preDT.svg" );
121  //We just iterate on the Domain points and print out the point coordinates.
122  std::copy ( image.begin(),
123  image.end(),
124  std::ostream_iterator<unsigned int> ( std::cout, " " ) );
125 
126  trace.info()<<std::endl;
127  for(int i=2;i<=15;++i)
128  {
129  for(int j=2;j<=15;++j)
130  trace.info()<< image(Point(i,j))<<" ";
131  trace.info()<<std::endl;
132  }
133 
134 
135  trace.warning() << dt << endl;
136  trace.info() <<std::endl;
137 
140 
141  for (; it != itend; ++it)
142  {
143  std::cout << (*it) << " ";
144  }
145  std::cout << std::endl;
146 
147  trace.info()<<std::endl;
148  for(int i=2;i<=15;++i)
149  {
150  for(int j=2;j<=15;++j)
151  trace.info()<< dt(Point(i,j))<<" ";
152  trace.info()<<std::endl;
153  }
154 
155 
156  trace.info()<<std::endl;
157  for(int i=2;i<=15;++i)
158  {
159  for(int j=2;j<=15;++j)
160  {
161  Point p= dt.getVoronoiVector(Point(i,j));
162  if (p==Point(i,j))
163  trace.info()<<"-,- ";
164  else
165  trace.info()<< p[0]<<","<<p[1]<<" ";
166  }
167  trace.info()<<std::endl;
168  }
169 
170 
171  allfine = true;
172 
173  trace.info()<<std::endl;
174  for(int i=2;i<=15;++i)
175  {
176  for(int j=2;j<=15;++j)
177  {
178  Point p= voro(Point(i,j));
179  if (p != dt.getVoronoiVector(Point(i,j)))
180  allfine = false;
181  if (p==Point(i,j))
182  trace.info()<<"-,- ";
183  else
184  trace.info()<< p[0]<<","<<p[1]<<" ";
185  }
186  trace.info()<<std::endl;
187  }
188 
189  board.clear();
190  Display2DFactory::drawImage<Gray>(board, dt, (DGtal::int64_t)0, (DGtal::int64_t)16);
191  board.saveSVG ( "image-postDT.svg" );
192  trace.info() << dt << endl;
193  trace.endBlock();
194 
195  return allfine;
196 }
void beginBlock(const std::string &keyword="")
Aim: Implementation of the linear in time Voronoi map construction.
Definition: VoronoiMap.h:126
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
void setUnit(Unit unit)
Definition: Board.cpp:240
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Image image(domain)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testDistanceTransformation3D()

bool testDistanceTransformation3D ( )

Example of a test. To be completed.

Definition at line 417 of file testDistanceTransformation.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), image(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

418 {
419  unsigned int nbok = 0;
420  unsigned int nb = 0;
421 
422  trace.beginBlock ( "Testing 3D DT computation" );
423 
424  typedef SpaceND<3> TSpace;
425  typedef TSpace::Point Point;
427  Point a ( 0, 0, 0 );
428  Point b ( 15, 15, 15 );
430  Image image ( Domain(a, b ));
431  Point c(8, 8, 8);
432  Domain dom(a, b);
433 
434  for (Domain::ConstIterator it = dom.begin(),
435  itend = dom.end(); it != itend; ++it)
436  {
437  if ( ((*it) - c).norm() < 7)
438  image.setValue ( *it, 128 );
439  }
440 
442  Predicate aPredicate(image,0);
443 
445  L2Metric l2;
446  DistanceTransformation<TSpace, Predicate, L2Metric> dt(&dom, &aPredicate,&l2);
447 
448  //We display the values on a 2D slice
449  for (unsigned int y = 0; y < 16; y++)
450  {
451  for (unsigned int x = 0; x < 16; x++)
452  {
453  Point p(x, y, 8);
454  std::cout << dt(p) << " ";
455  }
456  std::cout << std::endl;
457  }
458 
459 
460  trace.warning() << dt << endl;
461 
462  trace.endBlock();
463 
464  return nbok == nb;
465 }
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: implements separable l_p metrics with exact predicates.
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
ImageContainerBySTLVector< Domain, Value > Image
Image image(domain)

◆ testDistanceTransformationBorder()

bool testDistanceTransformationBorder ( )

Example of a test. To be completed.

Definition at line 344 of file testDistanceTransformation.cpp.

References DGtal::DefaultConstImageRange< TImage >::begin(), DGtal::Trace::beginBlock(), DGtal::DistanceTransformation< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::constRange(), DGtal::DefaultConstImageRange< TImage >::end(), DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), randomSeeds(), LibBoard::Board::setUnit(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

Referenced by main().

345 {
346  unsigned int nbok = 0;
347  unsigned int nb = 0;
348 
349  trace.beginBlock ( "Testing DT computation with Infinity values at the first step" );
350 
351  typedef SpaceND<2> TSpace;
352  typedef TSpace::Point Point;
355 
356  Point a (0, 0 );
357  Point b ( 128, 128 );
358 
360  Image image ( Domain(a, b ));
361 
362  for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
363  *it = 128 ;
364 
365 
366  randomSeeds(image, 19, 0);
367 
369  Predicate aPredicate(image,0);
370 
372  L2Metric l2;
373  Domain dom(a,b);
374  DistanceTransformation<TSpace, Predicate, L2Metric> dt(&dom, &aPredicate, &l2);
375 
376  Board2D board;
378  Display2DFactory::drawImage<Hue>(board, image, (unsigned int)0, (unsigned int)150);
379  board.saveSVG ( "image-preDT-border.svg" );
380 
382  for ( DistanceTransformation<TSpace, Predicate, L2Metric>::ConstRange::ConstIterator it = dt.constRange().begin(), itend = dt.constRange().end();it != itend; ++it)
383  if ( (*it) > maxv)
384  maxv = (*it);
385 
387  for (unsigned int y = 0; y < 33; y++)
388  {
389  for (unsigned int x = 0; x < 33; x++)
390  {
391  std::cout << std::setw(4) << (*it) << " ";
392  ++it;
393  }
394  std::cout << std::endl;
395  }
396 
397  trace.warning() << dt << "MaxV = " << maxv << endl;
398 
399 
400  board.clear();
401  Display2DFactory::drawImage<Hue>(board, dt, (DGtal::int64_t)0, (DGtal::int64_t)maxv+1);
402  board.saveSVG ( "image-postDT-border.svg" );
403 
404 
405  trace.info() << dt << endl;
406 
407  trace.endBlock();
408 
409  return nbok == nb;
410 }
void beginBlock(const std::string &keyword="")
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements separable l_p metrics with exact predicates.
void randomSeeds(Image &input, const unsigned int nb, const int value)
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
void setUnit(Unit unit)
Definition: Board.cpp:240
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Image image(domain)
SeparableMetric::Value Value
Definition of the image value type.
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testDistanceTransformationNeg()

bool testDistanceTransformationNeg ( )

Example of a test. To be completed.

Definition at line 201 of file testDistanceTransformation.cpp.

References DGtal::DefaultConstImageRange< TImage >::begin(), DGtal::Trace::beginBlock(), DGtal::DistanceTransformation< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::constRange(), DGtal::DistanceTransformation< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::domain(), DGtal::DefaultConstImageRange< TImage >::end(), DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), LibBoard::Board::setUnit(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

Referenced by main().

202 {
203  unsigned int nbok = 0;
204  unsigned int nb = 0;
205 
206  trace.beginBlock ( "Testing the Neg DT computation" );
207 
208  typedef Z2i::Space TSpace;
209  typedef TSpace::Point Point;
210  typedef Z2i::Domain Domain;
212  Point a ( -10, -10 );
213  Point b ( 10, 10 );
215  Image image ( Domain( a, b ));
216 
217  for(int y=-10; y<=10;y++)
218  for(int x=-10; x<=10;x++)
219  {
220  if ((abs(x)<7) && (abs(y)<5))
221  image.setValue(Point(x,y),1);
222  else
223  image.setValue(Point(x,y),0);
224  }
225 
227  Predicate aPredicate(image,0);
228 
230  L2Metric l2;
231  Board2D board;
233  Display2DFactory::drawImage<Gray>(board, image, (unsigned int)0, (unsigned int)1);
234  board.saveSVG ( "image-preDT-neg.svg" );
235 
236 
237  for(int y=-10; y<=10;y++)
238  {
239  for(int x=-10; x<=10;x++)
240  {
241  std::cout<<image(Point(x,y))<<" ";
242  }
243  std::cout<<std::endl;
244  }
245 
246  trace.info()<<"Domain "<<Domain(a,b)<<std::endl;
247  Domain dom(a,b);
248  DistanceTransformation<TSpace, Predicate , L2Metric> dt(&dom, &aPredicate, &l2);
249 
252  itend = dt.constRange().end();
253  it != itend ; ++it)
254  if ((*it) > maxv)
255  maxv = (*it);
256 
257  for(int y=-10; y<=10;y++)
258  {
259  for(int x=-10; x<=10;x++)
260  {
261  std::cout<<dt(Point(x,y))<<" ";
262  }
263  std::cout<<std::endl;
264  }
265 
266 
267 
268  trace.warning() << dt << endl;
269  trace.warning() << dt.domain() << endl;
270 
271 
272  trace.info() << "Exporting..." << endl;
273  board.clear();
274  Display2DFactory::drawImage<Gray>(board, dt, 0, maxv);
275  board.saveSVG ( "image-postDT-neg.svg" );
276 
277  trace.info() << "Done..." << endl;
278 
279  trace.info() << dt << endl;
280 
281  trace.endBlock();
282 
283  return nbok == nb;
284 }
void beginBlock(const std::string &keyword="")
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
HyperRectDomain< Space > Domain
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
double endBlock()
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
void setUnit(Unit unit)
Definition: Board.cpp:240
Image image(domain)
SeparableMetric::Value Value
Definition of the image value type.
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testDTFromSet()

bool testDTFromSet ( )

Definition at line 287 of file testDistanceTransformation.cpp.

References DGtal::Trace::beginBlock(), domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::AccFlower2D< TSpace >::getLowerBound(), DGtal::AccFlower2D< TSpace >::getUpperBound(), and DGtal::trace.

Referenced by main().

288 {
289  unsigned int nbok = 0;
290  unsigned int nb = 0;
291 
292  trace.beginBlock ( "Testing the whole DT computation from a Set" );
293 
294  typedef SpaceND<2> TSpace;
296 
297 
298  Board2D board;
299 
300  AccFlower2D<Z2i::Space> flower(Z2i::Point(0,0), 30, 5,2,0);
301  Z2i::Domain domain(flower.getLowerBound(), flower.getUpperBound());
302  Z2i::DigitalSet aSet(domain);
303 
305 
306  // Since 0.6, models of CDigitalSet are models of CPointPredicate.
307  // SetPredicate<Z2i::DigitalSet> aPredicate(aSet);
310  L2Metric l2;
311  L2DT dt(&domain,&aSet, &l2);
314  L1Metric l1;
315  L1DT dt1(&domain,&aSet, &l1);
316 
317  L2DT::Value maxv = 0;
318  for ( L2DT::ConstRange::ConstIterator it = dt.constRange().begin(), itend = dt.constRange().end();
319  it != itend; ++it)
320  if ( (*it) > maxv)
321  maxv = (*it);
322  trace.error() << "MaxV="<<maxv<<std::endl;
323  Display2DFactory::drawImage<Hue>(board, dt, 0, maxv+1);
324  board.saveSVG ( "image-DTSet.svg" );
325 
326  board.clear();
327  maxv = 0;
328  for ( L1DT::ConstRange::ConstIterator it = dt1.constRange().begin(), itend = dt1.constRange().end();
329  it != itend; ++it)
330  if ( (*it) > maxv)
331  maxv = (*it);
332  trace.error() << "MaxV="<<maxv<<std::endl;
333  Display2DFactory::drawImage<Hue>(board, dt1, 0, maxv+1);
334  board.saveSVG ( "image-DTSet-l1.svg" );
335  trace.endBlock();
336 
337  return nbok == nb;
338 }
void beginBlock(const std::string &keyword="")
ExactPredicateLpSeparableMetric< Space, 1 > L1Metric
Definition: StdDefs.h:119
Aim: Implementation of the linear in time distance transformation for separable metrics.
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements separable l_p metrics with exact predicates.
Aim: Model of the concept StarShaped represents any accelerated flower in the plane.
Definition: AccFlower2D.h:64
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
std::ostream & error()
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70