DGtal  1.1.0
imageGridCurveEstimator.cpp
1 
31 #include <iostream>
33 #include <fstream>
34 #include <algorithm>
36 
38 #include "DGtal/base/Common.h"
39 #include "DGtal/helpers/StdDefs.h"
40 #include "ConfigExamples.h"
42 
44 #include "DGtal/base/BasicFunctors.h"
45 #include "DGtal/kernel/BasicPointPredicates.h"
46 #include "DGtal/io/readers/PGMReader.h"
47 #include "DGtal/images/ImageContainerBySTLVector.h"
49 
51 #include "DGtal/topology/helpers/Surfaces.h"
53 
55 #include "DGtal/geometry/curves/estimation/DSSLengthEstimator.h"
57 
58 //display
59 #include "DGtal/io/boards/Board2D.h"
60 
61 //segmentation
62 #include "DGtal/geometry/curves/GreedySegmentation.h"
63 
65 
66 using namespace DGtal;
67 using namespace DGtal::functors;
68 
69 int main()
70 {
71  //image import
73  std::string filename = examplesPath + "samples/contourS.pgm";
74  Image image = DGtal::PGMReader<Image>::importPGM(filename);
75 
77  //predicate from the image
79  Binarizer b(1, 135);
80  PointFunctorPredicate<Image,Binarizer> predicate(image, b);
82 
84  Z2i::KSpace ks; //Khalimsky space
85  ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
86  SurfelAdjacency<2> sAdj( true ); //adjacency
88 
90  //extraction of all the contours
91  std::vector< std::vector< Z2i::SCell > > contours;
93  ::extractAll2DSCellContours( contours, ks, sAdj, predicate );
95 
96  if (contours.size() > 0)
97  {
98 
100  //init grid curve from the first retrieved contour
101  Z2i::Curve c;
102  c.initFromSCellsVector( contours.at(1) );
104 
106  //range of points
108  Range r = c.getPointsRange();
110 
112  //length estimation based on a DSS segmentation
114  trace.info() << "Length: " << DSSlength.eval(r.c(), r.c(), 1.) << std::endl;
116 
117  //DSS segmentation display
119  typedef GreedySegmentation<SegmentComputer> Segmentation;
120 
121  Segmentation theSegmentation( r.c(), r.c(), SegmentComputer() );
122  Segmentation::SegmentComputerIterator i = theSegmentation.begin();
123  Segmentation::SegmentComputerIterator end = theSegmentation.end();
124 
125  DGtal::Board2D aBoard;
126  aBoard << SetMode("PointVector", "Grid");
127  for ( ; i != end; ++i) {
128  SegmentComputer::Primitive dss = i->primitive();
129  aBoard << SetMode(dss.className(), "Points") << dss;
130  aBoard << SetMode(dss.className(), "BoundingBox") << dss;
131  }
132  aBoard.saveEPS("DisplayDSSSegmentationTuto3.eps");
133 
134  } else trace.info() << "no contour" << std::endl;
135 
136  return 0;
137 
138 }
139 
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition: ArithmeticalDSSComputer.h:87
DGtal::ConstRangeAdapter
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Definition: ConstRangeAdapter.h:87
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:127
DGtal::functors
functors namespace gathers all DGtal functors.
Definition: BasicBoolFunctors.h:49
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:66
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
DGtal::Trace::info
std::ostream & info()
DGtal::GreedySegmentation
Definition: GreedySegmentation.h:150
DGtal::GridCurve::initFromSCellsVector
bool initFromSCellsVector(const std::vector< SCell > &aVectorOfSCells)
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::PGMReader::importPGM
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:74
DGtal::DSSLengthEstimator
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Definition: DSSLengthEstimator.h:77
Range
Image::Range Range
Definition: testSimpleRandomAccessRangeFromPoint.cpp:46
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::DSSLengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::Surfaces::extractAll2DSCellContours
static void extractAll2DSCellContours(std::vector< std::vector< SCell > > &aVectSCellContour2D, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp)
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::functors::IntervalThresholder
Aim: A small functor with an operator () that compares one value to an interval.
Definition: BasicFunctors.h:701
DGtal::functors::PointFunctorPredicate
Aim: The predicate returns true when the predicate returns true for the value assigned to a given poi...
Definition: BasicPointPredicates.h:371
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:394