DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
freemanChainFromImage.cpp
1 
30 
31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include "ConfigExamples.h"
35 
37 #include "DGtal/io/readers/PNMReader.h"
38 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
40 
42 #include "DGtal/topology/helpers/Surfaces.h"
43 #include "DGtal/geometry/curves/FreemanChain.h"
45 
47 #include "DGtal/io/boards/Board2D.h"
48 #include "DGtal/io/colormaps/GradientColorMap.h"
49 #include "DGtal/io/Color.h"
51 
52 int main()
53 {
54 
57  std::string filename = examplesPath + "samples/circleR10modif.pgm";
58  Image image = DGtal::PNMReader<Image>::importPGM(filename);
60 
62  Z2i::KSpace ks;
63  ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
65 
67  Z2i::DigitalSet set2d (image.domain());
68  SetPredicate<Z2i::DigitalSet> set2dPredicate( set2d );
69  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 1, 255);
71 
72 
74  Board2D aBoard;
75  aBoard << set2d;
76  aBoard << image.domain();
78 
80  SurfelAdjacency<2> sAdj( true );
82 
84  std::vector< std::vector< Z2i::Point > > vectContoursBdryPointels;
85  Surfaces<Z2i::KSpace>::extractAllPointContours4C( vectContoursBdryPointels,
86  ks, set2dPredicate, sAdj );
88 
89 
90  GradientColorMap<int> cmap_grad( 0, (const int)vectContoursBdryPointels.size() );
91  cmap_grad.addColor( Color( 50, 50, 255 ) );
92  cmap_grad.addColor( Color( 255, 0, 0 ) );
93  cmap_grad.addColor( Color( 255, 255, 10 ) );
94  cmap_grad.addColor( Color( 25, 255, 255 ) );
95  cmap_grad.addColor( Color( 255, 25, 255 ) );
96  cmap_grad.addColor( Color( 25, 25, 25 ) );
97 
99  for(unsigned int i=0; i<vectContoursBdryPointels.size(); i++){
100  // Constructing and displaying FreemanChains from contours.
101  FreemanChain<Z2i::Integer> fc (vectContoursBdryPointels.at(i));
104  aBoard << SetMode( fc.className(), "InterGrid" );
105  aBoard<< CustomStyle( fc.className(),
106  new CustomColors( cmap_grad(i), Color::None ) );
107  aBoard << fc;
109  }
110 
111  aBoard.saveEPS("freemanChainFromImage.eps");
112  return 0;
113 }