DGtal  0.9.2
freemanChainFromImage.cpp
1 
30 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include "ConfigExamples.h"
35 
37 #include "DGtal/io/readers/PGMReader.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"
50 
51 using namespace DGtal;
53 
54 int main()
55 {
56 
59  std::string filename = examplesPath + "samples/circleR10modif.pgm";
60  Image image = DGtal::PGMReader<Image>::importPGM(filename);
62 
64  Z2i::KSpace ks;
65  ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
67 
69  Z2i::DigitalSet set2d (image.domain());
70  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 1, 255);
72 
73 
75  Board2D aBoard;
76  aBoard << set2d;
77  aBoard << image.domain();
79 
81  SurfelAdjacency<2> sAdj( true );
83 
85  std::vector< std::vector< Z2i::Point > > vectContoursBdryPointels;
86  Surfaces<Z2i::KSpace>::extractAllPointContours4C( vectContoursBdryPointels,
87  ks, set2d, sAdj );
89 
90 
91  GradientColorMap<int> cmap_grad( 0, (const int)vectContoursBdryPointels.size() );
92  cmap_grad.addColor( Color( 50, 50, 255 ) );
93  cmap_grad.addColor( Color( 255, 0, 0 ) );
94  cmap_grad.addColor( Color( 255, 255, 10 ) );
95  cmap_grad.addColor( Color( 25, 255, 255 ) );
96  cmap_grad.addColor( Color( 255, 25, 255 ) );
97  cmap_grad.addColor( Color( 25, 25, 25 ) );
98 
100  for(unsigned int i=0; i<vectContoursBdryPointels.size(); i++){
101  // Constructing and displaying FreemanChains from contours.
102  FreemanChain<Z2i::Integer> fc (vectContoursBdryPointels.at(i));
105  aBoard << SetMode( fc.className(), "InterGrid" );
106  aBoard<< CustomStyle( fc.className(),
107  new CustomColors( cmap_grad(i), Color::None ) );
108  aBoard << fc;
110  }
111 
112  aBoard.saveEPS("freemanChainFromImage.eps");
113  return 0;
114 }
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
static void extractAllPointContours4C(std::vector< std::vector< Point > > &aVectPointContour2D, const KSpace &aKSpace, const PointPredicate &pp, const SurfelAdjacency< 2 > &aSAdj)
void addColor(const Color &color)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
static const Color None
Definition: Color.h:387
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
bool init(const Point &lower, const Point &upper, bool isClosed)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
const Domain & domain() const
Definition: Image.h:192
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70