DGtal  1.3.beta
tutorial-examples/freemanChainFromImage.cpp

A simple example to show how to extract the set of boundary contours obtained from the image level set. This programm outputs this image:

#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/Color.h"
using namespace DGtal;
int main()
{
std::string filename = examplesPath + "samples/circleR10modif.pgm";
ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
Z2i::DigitalSet set2d (image.domain());
Board2D aBoard;
aBoard << set2d;
aBoard << image.domain();
SurfelAdjacency<2> sAdj( true );
std::vector< std::vector< Z2i::Point > > vectContoursBdryPointels;
ks, set2d, sAdj );
GradientColorMap<int> cmap_grad( 0, (int)vectContoursBdryPointels.size() );
cmap_grad.addColor( Color( 50, 50, 255 ) );
cmap_grad.addColor( Color( 255, 0, 0 ) );
cmap_grad.addColor( Color( 255, 255, 10 ) );
cmap_grad.addColor( Color( 25, 255, 255 ) );
cmap_grad.addColor( Color( 255, 25, 255 ) );
cmap_grad.addColor( Color( 25, 25, 25 ) );
for(unsigned int i=0; i<vectContoursBdryPointels.size(); i++){
// Constructing and displaying FreemanChains from contours.
FreemanChain<Z2i::Integer> fc (vectContoursBdryPointels.at(i));
aBoard << SetMode( fc.className(), "InterGrid" );
aBoard<< CustomStyle( fc.className(),
new CustomColors( cmap_grad(i), Color::None ) );
aBoard << fc;
}
aBoard.saveEPS("freemanChainFromImage.eps");
return 0;
}
DGtal::Surfaces::extractAllPointContours4C
static void extractAllPointContours4C(std::vector< std::vector< Point > > &aVectPointContour2D, const KSpace &aKSpace, const PointPredicate &pp, const SurfelAdjacency< 2 > &aSAdj)
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.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::FreemanChain::className
std::string className() const
DGtal::FreemanChain
Definition: FreemanChain.h:113
DGtal::CustomStyle
Definition: Board2D.h:217
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::PGMReader::importPGM
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
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
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::Color::None
static const Color None
Definition: Color.h:388
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64