DGtal 2.1.0
Loading...
Searching...
No Matches
volDTGranulo.cpp
Go to the documentation of this file.
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/PolyscopeViewer.h"
51#include "DGtal/io/colormaps/GradientColorMap.h"
52
53#include <boost/algorithm/minmax_element.hpp>
54
55using namespace DGtal;
56
57int main(int, char** argv)
58{
59 //Loarding the image
62 trace.info() << image << std::endl;
63
64 //Viewer
65 PolyscopeViewer<> viewer;
66
67 for(Image::Domain::ConstIterator it = image.domain().begin(),
68 itend = image.domain().end(); it != itend; ++it)
69 if (image(*it) != 0)
70 viewer << *it;
71
72 trace.info() << "viewer launched..."<<std::endl;
73 viewer.show();
74
75
76 //DT
79 Predicate binaryshape(image, 0);
80
82
83 DT distancemap(image.domain(), binaryshape, l2);
84
85 //Viewer
86 PolyscopeViewer<> viewer2;
87 trace.info() << "we display the dt map"<<std::endl;
88 int cpt=0;
89 viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
90
91 for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
92 itend = distancemap.domain().end(); it != itend;
93 ++it)
94 if (distancemap(*it) > 0)
95 {
96 viewer2 << DGtal::WithQuantity(*it, "value", distancemap(*it));
97 cpt++;
98 }
99 trace.info() << "Got "<<cpt<<" points."<<std::endl;
100 trace.info() << "viewer2 launched..."<<std::endl;
101 viewer2.show();
102
103 //Granulo
104 Image imageGranulo ( image.domain() );
105 for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
106 it != itend; ++it)
107 *it = 0;
108
109
110 trace.info() << "Computing the granulometry"<<std::endl;
111 cpt=0;
112 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
113 itend = imageGranulo.domain().end(); it != itend; ++it)
114 {
115 if (distancemap(*it) > 0)
116 {
117 //Construct the sphere with radius from distancemap(*it)
118 Z3i::RealPoint center = *it;
119 unsigned int radius = (unsigned int)distancemap(*it);
120 ImplicitBall<Z3i::Space> ball(center,radius);
123 Z3i::Domain dom(low,up);
124
125 for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
126 itball != itendball; itball++)
127 if (imageGranulo.domain().isInside(*itball) &&
128 ( ball(*itball) > 0) &&
129 (imageGranulo(*itball) < radius))
130 imageGranulo.setValue(*itball, radius);
131
132 cpt++;
133 }
134 }
135
136 trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
137 VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
138 trace.info() << "Save OK"<< std::endl;
139
140
141 //Viewer
142 PolyscopeViewer<> viewer3;
143
144 viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
145 cpt=0;
146 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
147 itend = imageGranulo.domain().end(); it != itend;
148 ++it)
149 if (imageGranulo(*it) > 0)
150 {
151 viewer3 << DGtal::WithQuantity(*it, "value", imageGranulo(*it));
152 cpt++;
153 }
154 trace.info() << "Got "<<cpt<<" points."<<std::endl;
155 trace.info() << "viewer3 launched..."<<std::endl;
156 viewer3.show();
157 return 0;
158
159}
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
Range range()
Definition Image.h:214
void setValue(const Point &aPoint, const Value &aValue)
Definition Image.h:247
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
RealPoint getUpperBound() const
RealPoint getLowerBound() const
Aim: Implements basic operations that will be used in Point and Vector classes.
static Self diagonal(Component val=1)
void show() override
Starts the event loop and display of elements.
std::ostream & info()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Clipping plane.
Definition Display3D.h:299
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: Export a 3D Image using the Vol formats.
Definition VolWriter.h:69
Attach a property to an element.
Definition Display3D.h:331
Functor that rounds up.
Functor that rounds down.
int main()
Definition testBits.cpp:56
Image image(domain)