DGtal 2.1.0
Loading...
Searching...
No Matches
imageGridCurveEstimator.cpp File Reference

An example of extracting a grid curve from an image iso-contour and estimating its length. More...

#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/kernel/BasicPointPredicates.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/geometry/curves/estimation/DSSLengthEstimator.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
Include dependency graph for imageGridCurveEstimator.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

An example of extracting a grid curve from an image iso-contour and estimating its length.

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr)
Date
2010/10/17

This file is part of the DGtal library.

Definition in file imageGridCurveEstimator.cpp.

Function Documentation

◆ main()

int main ( void  )

[imageGridCurveEstimator-predicate]

[imageGridCurveEstimator-predicate]

[imageGridCurveEstimator-prepareTracking]

[imageGridCurveEstimator-prepareTracking]

[imageGridCurveEstimator-tracking]

[imageGridCurveEstimator-tracking]

[imageGridCurveEstimator-instantiation]

[imageGridCurveEstimator-instantiation]

[imageGridCurveEstimator-getRange]

[imageGridCurveEstimator-getRange]

[imageGridCurveEstimator-lengthEstimation]

[imageGridCurveEstimator-lengthEstimation]

Definition at line 69 of file imageGridCurveEstimator.cpp.

70{
71 //image import
73 std::string filename = examplesPath + "samples/contourS.pgm";
75
77 //predicate from the image
79 Binarizer b(1, 135);
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
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}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
std::string className() const
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
PointsRange getPointsRange() const
Definition GridCurve.h:418
bool initFromSCellsVector(const std::vector< SCell > &aVectorOfSCells)
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
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,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & info()
Aim: A small functor with an operator () that compares one value to an interval.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
Trace trace
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
Aim: The predicate returns true when the predicate returns true for the value assigned to a given poi...
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation
Image image(domain)

References DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::className(), DGtal::Image< TImageContainer >::domain(), DGtal::DSSLengthEstimator< TConstIterator >::eval(), DGtal::GridCurve< TKSpace >::getPointsRange(), image(), DGtal::PGMReader< TImageContainer, TFunctor >::importPGM(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GridCurve< TKSpace >::initFromSCellsVector(), LibBoard::Board::saveEPS(), and DGtal::trace.