DGtal  0.9.2
FMMErosion.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "ConfigExamples.h"
35 
36 //image
37 #include "DGtal/images/ImageContainerBySTLVector.h"
38 #include "DGtal/images/ImageContainerBySTLMap.h"
39 #include "DGtal/base/BasicFunctors.h"
40 #include "DGtal/kernel/BasicPointPredicates.h"
41 
42 //IO
43 #include "DGtal/io/readers/VolReader.h"
44 #include "DGtal/io/writers/VolWriter.h"
45 
46 //frontier
47 #include "DGtal/topology/SurfelAdjacency.h"
48 #include "DGtal/topology/helpers/FrontierPredicate.h"
49 #include "DGtal/topology/LightExplicitDigitalSurface.h"
50 
51 // FMM
52 #include "DGtal/geometry/volumes/distance/FMM.h"
53 
55 
56 using namespace std;
57 using namespace DGtal;
58 using namespace Z3i;
59 
61 
62 
64 int main( int argc, char** argv )
65 {
66  trace.beginBlock ( "Example FMMErosion" );
67  trace.info() << "Args:";
68  for ( int i = 0; i < argc; ++i )
69  trace.info() << " " << argv[ i ];
70  trace.info() << endl;
71 
72  DGtal::trace.beginBlock("image reading...");
73 
75  string imageFileName = examplesPath + "samples/cat10.vol";
76  trace.info() << imageFileName <<std::endl;
77  typedef ImageContainerBySTLVector<Domain, bool> BinaryImage;
78  BinaryImage binaryImage = VolReader<BinaryImage>::importVol( imageFileName);
80 
82 
83  DGtal::trace.beginBlock("Search for a bel...");
84 
85  //space and starting bel
87  KSpace ks;
88  Domain domain = binaryImage.domain();
89  ks.init( domain.lowerBound(), domain.upperBound(), true );
90  KSpace::SCell bel;
91 
92  try {
93  //getting a bel
94  bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
95  trace.info() << "starting bel: " << bel << std::endl;
96 
97  } catch (DGtal::InputException i) {
98  trace.emphase() << "starting bel not found" << std::endl;
99  return 0;
100  }
102 
104 
105  DGtal::trace.beginBlock("Implicit frontier...");
106 
107  //implicit frontier
109  typedef functors::FrontierPredicate<KSpace, BinaryImage> SurfelPredicate;
111  functors::SCellToIncidentPoints<KSpace> toIncidentPoints( ks );
112  std::pair<Point,Point> bpair = toIncidentPoints( bel );
113  SurfelPredicate surfelPredicate( ks, binaryImage,
114  binaryImage( bpair.first ),
115  binaryImage( bpair.second ) );
116  Frontier frontier( ks, surfelPredicate,
117  SurfelAdjacency<KSpace::dimension>( true ), bel );
119 
121 
122  const double maximalDistance = 3.0;
123 
124  DGtal::trace.beginBlock("FMM...");
125 
127  typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
128  typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
131 
133  DistanceImage imageDistance( domain, 0.0 );
134  AcceptedPointSet pointSet( imageDistance );
135  functors::SCellToInnerPoint<KSpace> toInnerPoint( ks );
136  for (Frontier::SurfelConstIterator it = frontier.begin(), itEnd = frontier.end();
137  it != itEnd; ++it)
138  {
139  pointSet.insert( toInnerPoint(*it) );
140  imageDistance.setValue( toInnerPoint(*it), 0.5 );
141  }
143 
145  FMM fmm( imageDistance, pointSet, binaryImage,
146  domain.size(), maximalDistance );
147  fmm.compute();
148  trace.info() << fmm << std::endl;
150 
152 
153  DGtal::trace.beginBlock("Erosion");
154  trace.info() << "Erosion of radius: " << maximalDistance << std::endl;
155 
157  for (AcceptedPointSet::ConstIterator it = pointSet.begin(), itEnd = pointSet.end();
158  it != itEnd; ++it)
159  {
160  binaryImage.setValue(*it, 0);
161  }
163 
165 
166  DGtal::trace.beginBlock("image writing...");
167 
169  string outputFileName = "eroded.vol";
170  trace.info() << "to " << outputFileName << std::endl;
171  VolWriter<BinaryImage,functors::Cast<unsigned char> >::exportVol(outputFileName, binaryImage);
173 
175 
176 
177  trace.endBlock();
178  return 0;
179 }
180 // //
void beginBlock(const std::string &keyword="")
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: The predicate on surfels that represents the frontier between two regions in an image...
Trace trace
Definition: Common.h:130
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:68
STL namespace.
double endBlock()
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
std::ostream & emphase()
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
const Point & lowerBound() const
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...