DGtal  1.4.2
FMMErosion.cpp
Go to the documentation of this file.
1 
31 #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, (unsigned int)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 // //
int main(int argc, char **argv)
Definition: FMMErosion.cpp:64
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:151
void compute()
const Point & lowerBound() const
const Point & upperBound() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Aim: The predicate on surfels that represents the frontier between two regions in an image....
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:69
Domain domain