DGtal  1.3.beta
tutorial-examples/FMMErosion.cpp

Example of tutorial 1: Local morphological opening of a 3d volume by the Fast Marching Method

See also
Tutorial: Local morphological opening of a 3d volume by the Fast Marching Method
erosion using FMM.
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigExamples.h"
//image
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/kernel/BasicPointPredicates.h"
//IO
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/VolWriter.h"
//frontier
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
// FMM
#include "DGtal/geometry/volumes/distance/FMM.h"
using namespace std;
using namespace DGtal;
using namespace Z3i;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example FMMErosion" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
DGtal::trace.beginBlock("image reading...");
string imageFileName = examplesPath + "samples/cat10.vol";
trace.info() << imageFileName <<std::endl;
BinaryImage binaryImage = VolReader<BinaryImage>::importVol( imageFileName);
DGtal::trace.beginBlock("Search for a bel...");
//space and starting bel
KSpace ks;
Domain domain = binaryImage.domain();
ks.init( domain.lowerBound(), domain.upperBound(), true );
try {
//getting a bel
bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
trace.info() << "starting bel: " << bel << std::endl;
} catch (DGtal::InputException& i) {
trace.emphase() << "starting bel not found" << std::endl;
return 0;
}
DGtal::trace.beginBlock("Implicit frontier...");
//implicit frontier
std::pair<Point,Point> bpair = toIncidentPoints( bel );
SurfelPredicate surfelPredicate( ks, binaryImage,
binaryImage( bpair.first ),
binaryImage( bpair.second ) );
Frontier frontier( ks, surfelPredicate,
const double maximalDistance = 3.0;
typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
DistanceImage imageDistance( domain, 0.0 );
AcceptedPointSet pointSet( imageDistance );
for (Frontier::SurfelConstIterator it = frontier.begin(), itEnd = frontier.end();
it != itEnd; ++it)
{
pointSet.insert( toInnerPoint(*it) );
imageDistance.setValue( toInnerPoint(*it), 0.5 );
}
FMM fmm( imageDistance, pointSet, binaryImage,
domain.size(), maximalDistance );
fmm.compute();
trace.info() << fmm << std::endl;
DGtal::trace.beginBlock("Erosion");
trace.info() << "Erosion of radius: " << maximalDistance << std::endl;
for (AcceptedPointSet::ConstIterator it = pointSet.begin(), itEnd = pointSet.end();
it != itEnd; ++it)
{
binaryImage.setValue(*it, 0);
}
DGtal::trace.beginBlock("image writing...");
string outputFileName = "eroded.vol";
trace.info() << "to " << outputFileName << std::endl;
VolWriter<BinaryImage,functors::Cast<unsigned char> >::exportVol(outputFileName, binaryImage);
return 0;
}
// //
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::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::HyperRectDomain::size
Size size() const
Definition: HyperRectDomain.h:565
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
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::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
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::FMM
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
DGtal::LightExplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: LightExplicitDigitalSurface.h:118
DGtal::Trace::info
std::ostream & info()
DGtal::VolWriter
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:68
DGtal::FMM::compute
void compute()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::functors::FrontierPredicate
Aim: The predicate on surfels that represents the frontier between two regions in an image....
Definition: FrontierPredicate.h:67
DGtal::functors::SCellToInnerPoint
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Definition: SCellsFunctors.h:323
DGtal::DigitalSetFromMap
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Definition: DigitalSetFromMap.h:74
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::functors::SCellToIncidentPoints
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Definition: SCellsFunctors.h:474
DGtal::InputException
Definition: Exceptions.h:63
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64