DGtal  1.5.beta
FMMErosion.cpp File Reference
#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"
Include dependency graph for FMMErosion.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/06/19

An example file named FMMErosion.

This file is part of the DGtal library.

Definition in file FMMErosion.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[FMMErosionImageReading]

[FMMErosionImageReading]

[FMMErosionStartingBel]

[FMMErosionStartingBel]

[FMMErosionTracking]

[FMMErosionTracking]

[FMMErosionFMMTypes]

[FMMErosionFMMTypes]

[FMMErosionFMMInit]

[FMMErosionFMMInit]

[FMMErosionFMM]

[FMMErosionFMM]

[FMMErosionErosion]

[FMMErosionErosion]

[FMMErosionImageWriting]

[FMMErosionImageWriting]

Definition at line 64 of file FMMErosion.cpp.

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 }
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
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
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

References DGtal::Trace::beginBlock(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::compute(), domain, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::HyperRectDomain< TSpace >::size(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().