DGtal 2.0.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 argc, char ** argv)
58{
59
60 //Loarding the image
63 trace.info() << image << std::endl;
64
65 //Viewer
66 PolyscopeViewer<> viewer;
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 trace.info() << "viewer launched..."<<std::endl;
74 viewer.show();
75
76
77 //DT
80 Predicate binaryshape(image, 0);
81
83
84 DT distancemap(image.domain(), binaryshape, l2);
85
86 //Viewer
87 PolyscopeViewer<> viewer2;
88 DT::Value maxDT = (*boost::first_max_element(distancemap.constRange().begin(),
89 distancemap.constRange().end()));
90 trace.info() << "we display the dt map"<<std::endl;
91 int cpt=0;
92 viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
93
94 for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
95 itend = distancemap.domain().end(); it != itend;
96 ++it)
97 if (distancemap(*it) > 0)
98 {
99 viewer2 << DGtal::WithQuantity(*it, "value", distancemap(*it));
100 cpt++;
101 }
102 trace.info() << "Got "<<cpt<<" points."<<std::endl;
103 trace.info() << "viewer2 launched..."<<std::endl;
104 viewer2.show();
105
106 //Granulo
107 Image imageGranulo ( image.domain() );
108 for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
109 it != itend; ++it)
110 *it = 0;
111
112
113 trace.info() << "Computing the granulometry"<<std::endl;
114 cpt=0;
115 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
116 itend = imageGranulo.domain().end(); it != itend; ++it)
117 {
118 if (distancemap(*it) > 0)
119 {
120 //Construct the sphere with radius from distancemap(*it)
121 Z3i::RealPoint center = *it;
122 unsigned int radius = (unsigned int)distancemap(*it);
123 ImplicitBall<Z3i::Space> ball(center,radius);
126 Z3i::Domain dom(low,up);
127
128 for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
129 itball != itendball; itball++)
130 if (imageGranulo.domain().isInside(*itball) &&
131 ( ball(*itball) > 0) &&
132 (imageGranulo(*itball) < radius))
133 imageGranulo.setValue(*itball, radius);
134
135 cpt++;
136 }
137 }
138
139 trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
140 VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
141 trace.info() << "Save OK"<< std::endl;
142
143
144 //Viewer
145 PolyscopeViewer<> viewer3;
146 Image::Value maxG = (*boost::first_max_element(imageGranulo.constRange().begin(),
147 imageGranulo.constRange().end()));
148
149 viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
150 cpt=0;
151 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
152 itend = imageGranulo.domain().end(); it != itend;
153 ++it)
154 if (imageGranulo(*it) > 0)
155 {
156 viewer3 << DGtal::WithQuantity(*it, "value", imageGranulo(*it));
157 cpt++;
158 }
159 trace.info() << "Got "<<cpt<<" points."<<std::endl;
160 trace.info() << "viewer3 launched..."<<std::endl;
161 viewer3.show();
162 return 0;
163
164}
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
ConstRange constRange() const
Definition Image.h:203
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:327
Functor that rounds up.
Functor that rounds down.
int main()
Definition testBits.cpp:56
Image image(domain)