DGtal 1.3.0
No Matches

This example outputs a greedy segmentation of a closed and 4-connected digital curve into DSSs.

* $ ./examples/geometry/curves/greedy-dss-decomposition
Greedy segmentation into DSSs
See also
Digital straight lines and segments
and Analysis of one-dimensional discrete structures
#include <cmath>
#include <iostream>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
using namespace std;
using namespace DGtal;
using namespace Z2i;
int main( )
trace.beginBlock ( "Example dgtalboard-5-greedy-dss" );
typedef FreemanChain<int> Contour4;
typedef GreedySegmentation<DSS4> Decomposition4;
// A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements.
std::stringstream ss(stringstream::in | stringstream::out);
ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
// Construct the Freeman chain
Contour4 theContour( ss );
// Segmentation
Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );
// Draw the domain and the contour
Point p1( 0, 0 );
Point p2( 31, 31 );
Domain domain( p1, p2 );
Board2D aBoard;
aBoard << SetMode( domain.className(), "Grid" )
<< domain
<< SetMode( "PointVector", "Grid" );
// Draw each segment
string styleName = "";
for ( Decomposition4::SegmentComputerIterator
it = theDecomposition.begin(),
itEnd = theDecomposition.end();
it != itEnd; ++it )
aBoard << SetMode( "ArithmeticalDSS", "Points" )
<< it->primitive();
aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" )
<< CustomStyle( "ArithmeticalDSS/BoundingBox",
new CustomPenColor( Color::Blue ) )
<< it->primitive();
return 0;
// //
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
void beginBlock(const std::string &keyword="")
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:313
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain