DGtal  1.2.0
freemanChainDisplay.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <fstream>
33 #include "DGtal/base/Common.h"
35 
36 
37 #include "DGtal/kernel/domains/HyperRectDomain.h"
38 #include "DGtal/images/ImageSelector.h"
39 #include "DGtal/kernel/SpaceND.h"
40 #include "DGtal/base/BasicTypes.h"
41 #include "DGtal/geometry/curves/FreemanChain.h"
42 #include "DGtal/io/readers/MagickReader.h"
43 #include "DGtal/io/boards/Board2D.h"
44 #include "DGtal/helpers/StdDefs.h"
45 
46 
47 
48 #include "ConfigExamples.h"
49 
50 
51 using namespace std;
52 using namespace DGtal;
53 using namespace Z2i;
54 
55 
56 
58 
59 int main()
60 {
61 
62  typedef SpaceND<2> Space2;
63  typedef HyperRectDomain<Space2> TDomain;
64 
65  //Default image selector = STLVector
67 
68 
69  // Creating FreemanChain from file
70  std::string freemanChainFilename = examplesPath + "samples/contourS.fc";
71  fstream fst;
72  fst.open (freemanChainFilename.c_str(), ios::in);
74  fst.close();
75 
76 
77  // Importing image with MagickReader
78  MagickReader<Image> reader;
79  std::string filenameImage = examplesPath + "samples/contourS.gif";
80  Image img = reader.importImage( filenameImage );
81 
82  Point ptInf = img.domain().lowerBound();
83  Point ptSup = img.domain().upperBound();
84  unsigned int width = abs(ptSup[0]-ptInf[0]+1);
85  unsigned int height = abs(ptSup[1]-ptInf[1]+1);
86 
87  // Draw the freemanchain and the contour
88  Board2D dgBoard;
89 
90  dgBoard.drawImage(filenameImage, 0,height-1, width, height );
91  dgBoard << fc;
92 
93  dgBoard.saveEPS("freemanChainDisplay.eps");
94  dgBoard.saveSVG("freemanChainDisplay.svg");
95  dgBoard.saveFIG("freemanChainDisplay.fig");
96 
97 
98  return 0;
99 }
100 // //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void drawImage(std::string filename, double x, double y, double width, double height, int depthValue=-1, double alpha=1.0)
Definition: Board.cpp:428
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
int main()
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: implements methods to read a 2D image using the ImageMagick library.
Definition: MagickReader.h:112
static ImageContainer importImage(const std::string &filename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
ImageContainerBySTLVector< Domain, Value > Image