DGtal  1.3.beta
topology/ctopo-fillContours.cpp

A simple example illustrating the filling of the interior/exterior of a given 2D contour. This program outputs these images:

See also
Filling oriented digital contours
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/SurfelSetPredicate.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
int main( int /*argc*/, char** /*argv*/ )
{
trace.beginBlock ( "Example ctopo-fillContours" );
K.init(Z2i::Point(0, 10), Z2i::Point(20, 30), false);
// We choose a direct and indirect oriented contour.
FreemanChain<int> fc1 ("001001001001001111101111011222222223222222322233333330301033333003", 6, 14);
FreemanChain<int> fc2 ("1111000033332222", 6, 20);
Board2D aBoard;
Board2D aBoard2;
aBoard << K.lowerBound() << K.upperBound() ;
aBoard2 << K.lowerBound() << K.upperBound() ;
//From the FreemanChain we can get a vector of SCell wrapped in a SurfelSetPredicate with sign defined from the FreemanChain orientation:
std::set<DGtal::KhalimskySpaceND< 2, int >::SCell> boundarySCell;
FreemanChain<int>::getInterPixelLinels(K, fc1, boundarySCell, false);
aBoard << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Red, DGtal::Color::Red) );
for( std::set<DGtal::KhalimskySpaceND< 2, int >::SCell>::const_iterator it= boundarySCell.begin();
it!= boundarySCell.end(); it++){
aBoard << *it;
}
// We can also add other freeman chains with indirect orientation to construct a hole in interior of the shape:
std::set<DGtal::KhalimskySpaceND< 2, int >::SCell> boundarySCellhole;
FreemanChain<int>::getInterPixelLinels(K, fc2, boundarySCellhole, false);
aBoard << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Blue, DGtal::Color::Blue) );
aBoard2 << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Blue, DGtal::Color::Blue) );
for( std::set<DGtal::KhalimskySpaceND< 2, int >::SCell>::const_iterator it= boundarySCellhole.begin(); it!= boundarySCellhole.end(); it++){
aBoard << *it;
aBoard2 << *it;
boundarySCell.insert(*it);
}
// Now we can compute the unsigned cell associated to interior pixels:
BoolImage2D::Domain imageDomain( Z2i::Point(0,10), Z2i::Point(20,30) );
BoolImage2D interiorCellImage( imageDomain );
Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillInterior(K, functors::SurfelSetPredicate<std::set<SCell>,SCell>(boundarySCell),
interiorCellImage, 1, false);
aBoard << CustomStyle(K.lowerCell().className(), new CustomColors(DGtal::Color::None, Color(200, 200, 200)) );
for(BoolImage2D::Domain::ConstIterator it = interiorCellImage.domain().begin();
it!=interiorCellImage.domain().end(); it++){
if(interiorCellImage(*it)){
aBoard << K.uSpel(*it);
}
}
// We can also compute the unsigned cell associated to interior and exterior pixels:
BoolImage2D interiorCellHoleImage( imageDomain );
BoolImage2D exteriorCellHoleImage( imageDomain );
Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillInterior(K, functors::SurfelSetPredicate<std::set<SCell>, SCell>(boundarySCellhole),
interiorCellHoleImage, 1, true);
Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillExterior(K, functors::SurfelSetPredicate<std::set<SCell>, SCell>(boundarySCellhole),
exteriorCellHoleImage, 1, false);
aBoard2 << CustomStyle(K.lowerCell().className(),
new CustomColors(DGtal::Color::None, Color(200, 200, 200)) );
for(BoolImage2D::Domain::ConstIterator it = interiorCellHoleImage.domain().begin();
it!=interiorCellHoleImage.domain().end(); it++){
if(interiorCellHoleImage(*it)){
aBoard2 << K.uSpel(*it);
}
}
aBoard2 << CustomStyle(K.lowerCell().className(),
new CustomColors(DGtal::Color::None, Color(100, 100, 100)) );
for(BoolImage2D::Domain::ConstIterator it = exteriorCellHoleImage.domain().begin();
it!=exteriorCellHoleImage.domain().end(); it++){
if(exteriorCellHoleImage(*it)){
aBoard2 << K.uSpel(*it);
}
}
aBoard.saveEPS("example_ctopo-fillContours.eps");
aBoard.saveFIG("example_ctopo-fillContours.fig");
aBoard2.saveEPS("example_ctopo-fillContours2.eps");
aBoard2.saveFIG("example_ctopo-fillContours2.fig");
return 0;
}
// //
DGtal::KhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::KhalimskySpaceND::upperBound
const Point & upperBound() const
Return the upper bound for digital points in this space.
DGtal::Trace::endBlock
double endBlock()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::KhalimskySpaceND::uSpel
Cell uSpel(Point p) const
From the digital coordinates of a point in Zn, builds the corresponding spel (cell of maximal dimensi...
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::KhalimskySpaceND::lowerCell
const Cell & lowerCell() const
Return the lower bound for cells in this space.
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::FreemanChain< int >
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::KhalimskySpaceND::lowerBound
const Point & lowerBound() const
Return the lower bound for digital points in this space.
DGtal::Color::Blue
static const Color Blue
Definition: Color.h:395
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::ImageContainerBySTLMap
Definition: ImageContainerBySTLMap.h:96
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::Color::Red
static const Color Red
Definition: Color.h:392
DGtal::functors::SurfelSetPredicate
Aim: The predicate returning true iff the point is in the domain given at construction.
Definition: SurfelSetPredicate.h:64
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
LibBoard::Board::saveFIG
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
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
DGtal::PointVector< dim, Integer >
DGtal::Color::None
static const Color None
Definition: Color.h:388
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64