Example of tutorial 1: Local morphological opening of a 3d volume by the Fast Marching Method
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigExamples.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/kernel/BasicPointPredicates.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/VolWriter.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
#include "DGtal/geometry/volumes/distance/FMM.h"
using namespace std;
using namespace Z3i;
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
string imageFileName = examplesPath + "samples/cat10.vol";
typedef ImageContainerBySTLVector<Domain, bool> BinaryImage;
BinaryImage binaryImage = VolReader<BinaryImage>::importVol( imageFileName);
try {
bel = Surfaces<KSpace>::findABel( ks, binaryImage, (
unsigned int)
domain.size() );
trace.
info() <<
"starting bel: " << bel << std::endl;
return 0;
}
typedef functors::FrontierPredicate<KSpace, BinaryImage> SurfelPredicate;
typedef LightExplicitDigitalSurface<KSpace, SurfelPredicate> Frontier;
functors::SCellToIncidentPoints<KSpace> toIncidentPoints( ks );
std::pair<Point,Point> bpair = toIncidentPoints( bel );
SurfelPredicate surfelPredicate( ks, binaryImage,
binaryImage( bpair.first ),
binaryImage( bpair.second ) );
Frontier frontier( ks, surfelPredicate,
SurfelAdjacency<KSpace::dimension>( true ), bel );
const double maximalDistance = 3.0;
typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef FMM<DistanceImage, AcceptedPointSet, BinaryImage > FMM;
DistanceImage imageDistance(
domain, 0.0 );
AcceptedPointSet pointSet( imageDistance );
functors::SCellToInnerPoint<KSpace> toInnerPoint( ks );
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() <<
"Erosion of radius: " << maximalDistance << std::endl;
it != itEnd; ++it)
{
binaryImage.setValue(*it, 0);
}
string outputFileName = "eroded.vol";
trace.
info() <<
"to " << outputFileName << std::endl;
VolWriter<BinaryImage,functors::Cast<unsigned char> >::exportVol(outputFileName, binaryImage);
return 0;
}
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain