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