DGtal  0.9.4.1
volDTGranulo.cpp
1 
31 #include <iostream>
33 #include <fstream>
34 #include <algorithm>
36 
37 #include "DGtal/base/Common.h"
38 #include "DGtal/helpers/StdDefs.h"
39 
40 #include "DGtal/images/ImageContainerBySTLVector.h"
41 
42 #include "DGtal/io/readers/VolReader.h"
43 #include "DGtal/io/writers/VolWriter.h"
44 
45 #include "DGtal/images/SimpleThresholdForegroundPredicate.h"
46 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
47 #include "DGtal/shapes/implicit/ImplicitBall.h"
48 #include "DGtal/base/BasicFunctors.h"
49 
50 #include "DGtal/io/viewers/Viewer3D.h"
51 #include "DGtal/io/colormaps/GradientColorMap.h"
52 
53 using namespace DGtal;
54 
55 int main(int argc, char ** argv)
56 {
57 
58  //Loarding the image
60  Image image = VolReader<Image>::importVol(argv[1]);
61  trace.info() << image << std::endl;
62 
63  //Viewer
64  QApplication application(argc,argv);
65  Viewer3D<> viewer;
66  viewer.show();
67 
68  for(Image::Domain::ConstIterator it = image.domain().begin(),
69  itend = image.domain().end(); it != itend; ++it)
70  if (image(*it) != 0)
71  viewer << *it;
72 
73  viewer << DGtal::Viewer3D<>::updateDisplay;
74  trace.info() << "viewer launched..."<<std::endl;
75  bool res = application.exec();
76 
77 
78  //DT
79  Z3i::L2Metric l2;
81  Predicate binaryshape(image, 0);
82 
84 
85  DT distancemap(image.domain(), binaryshape, l2);
86 
87  //Viewer
88  QApplication application2(argc,argv);
89  Viewer3D<> viewer2;
90  viewer2.show();
91  DT::Value maxDT = (*std::max_element(distancemap.constRange().begin(),
92  distancemap.constRange().end()));
93  GradientColorMap<DT::Value> gradient( 0, maxDT);
94  gradient.addColor(DGtal::Color::Blue);
95  gradient.addColor(DGtal::Color::Green);
96  gradient.addColor(DGtal::Color::Yellow);
97  gradient.addColor(DGtal::Color::Red);
98  trace.info() << "we display the dt map"<<std::endl;
99  int cpt=0;
100  viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
101 
102  for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
103  itend = distancemap.domain().end(); it != itend;
104  ++it)
105  if (distancemap(*it) > 0)
106  {
107  DT::Value val= distancemap( *it );
108  DGtal::Color c= gradient(val);
109 
110  viewer2 << DGtal::CustomColors3D(c,c) << *it ;
111  cpt++;
112  }
113  trace.info() << "Got "<<cpt<<" points."<<std::endl;
114  viewer2 << DGtal::Viewer3D<>::updateDisplay;
115  trace.info() << "viewer2 launched..."<<std::endl;
116  res = res && application2.exec();
117 
118  //Granulo
119  Image imageGranulo ( image.domain() );
120  for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
121  it != itend; ++it)
122  *it = 0;
123 
124 
125  trace.info() << "Computing the granulometry"<<std::endl;
126  cpt=0;
127  for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
128  itend = imageGranulo.domain().end(); it != itend; ++it)
129  {
130  if (distancemap(*it) > 0)
131  {
132  //Construct the sphere with radius from distancemap(*it)
133  Z3i::RealPoint center = *it;
134  unsigned int radius = (unsigned int)distancemap(*it);
135  ImplicitBall<Z3i::Space> ball(center,radius);
136  Z3i::Point low = center - Z3i::Point::diagonal( radius+1 );
137  Z3i::Point up = center + Z3i::Point::diagonal( radius+1 );
138  Z3i::Domain dom(low,up);
139 
140 
141  for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
142  itball != itendball; itball++)
143  if (imageGranulo.domain().isInside(*itball) &&
144  ( ball(*itball) > 0) &&
145  (imageGranulo(*itball) < radius))
146  imageGranulo.setValue(*itball, radius);
147 
148  cpt++;
149  }
150  }
151 
152  trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
153  VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
154  trace.info() << "Save OK"<< std::endl;
155 
156 
157  //Viewer
158  QApplication application3(argc,argv);
159  Viewer3D<> viewer3;
160  viewer3.show();
161  Image::Value maxG = (*std::max_element(imageGranulo.constRange().begin(),
162  imageGranulo.constRange().end()));
163  GradientColorMap<Image::Value> gradient2( 0, maxG);
164  gradient2.addColor(DGtal::Color::Blue);
165  gradient2.addColor(DGtal::Color::Green);
166  gradient2.addColor(DGtal::Color::Yellow);
167  gradient2.addColor(DGtal::Color::Red);
168  viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
169  cpt=0;
170  for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
171  itend = imageGranulo.domain().end(); it != itend;
172  ++it)
173  if (imageGranulo(*it) > 0)
174  {
175  Image::Value val= imageGranulo( *it );
176  DGtal::Color c = gradient2(val);
177  viewer3 << DGtal::CustomColors3D(c,c) << *it ;
178  cpt++;
179  }
180  trace.info() << "Got "<<cpt<<" points."<<std::endl;
181  viewer3 << DGtal::Viewer3D<>::updateDisplay;
182  trace.info() << "viewer3 launched..."<<std::endl;
183  return application3.exec();
184 
185 }
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
static Self diagonal(Component val=1)
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:68
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
static const Color Yellow
Definition: Color.h:397
Aim: implements separable l_p metrics with exact predicates.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
static const Color Blue
Definition: Color.h:394
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
int main(int argc, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
static const Color Red
Definition: Color.h:391
Class for adding a Clipping plane through the Viewer3D stream. Realizes the concept CDrawableWithView...
static const Color Green
Definition: Color.h:392
Image image(domain)