DGtal  1.3.beta
geometry/curves/greedy-dss-decomposition.cpp

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
geometry/curves/greedy-dss-decomposition.cpp
#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();
}
aBoard.saveSVG("greedy-dss-decomposition.svg");
aBoard.saveEPS("greedy-dss-decomposition.eps");
#ifdef WITH_CAIRO
aBoard.saveCairo("greedy-dss-decomposition.png");
#endif
return 0;
}
// //
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition: ArithmeticalDSSComputer.h:86
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::FreemanChain< int >
DGtal::HyperRectDomain::className
std::string className() const
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::GreedySegmentation
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Definition: GreedySegmentation.h:149
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::CustomPenColor
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:312