DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
volDTGranulo.cpp
Go to the documentation of this file.
1
16
30
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
55
using namespace
DGtal
;
56
57
int
main
(
int
,
char
** argv)
58
{
59
//Loarding the image
60
typedef
ImageContainerBySTLVector<Z3i::Domain, unsigned int>
Image
;
61
Image
image
=
VolReader<Image>::importVol
(argv[1]);
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
77
Z3i::L2Metric
l2;
78
typedef
functors::SimpleThresholdForegroundPredicate<Image>
Predicate;
79
Predicate binaryshape(
image
, 0);
80
81
typedef
DistanceTransformation< Z3i::Space, Predicate, Z3i::L2Metric>
DT;
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);
121
Z3i::Point
low(ball.
getLowerBound
() -
Z3i::RealPoint::diagonal
(1.0),
functors::Floor<>
());
122
Z3i::Point
up (ball.
getUpperBound
() +
Z3i::RealPoint::diagonal
(1.0),
functors::Ceil<>
());
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
}
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::HyperRectDomain::isInside
bool isInside(const Point &p) const
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition
HyperRectDomain.h:176
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition
HyperRectDomain.h:201
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition
ImageContainerBySTLVector.h:264
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::Image::range
Range range()
Definition
Image.h:214
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition
ImplicitBall.h:65
DGtal::ImplicitBall::getUpperBound
RealPoint getUpperBound() const
Definition
ImplicitBall.h:120
DGtal::ImplicitBall::getLowerBound
RealPoint getLowerBound() const
Definition
ImplicitBall.h:114
DGtal::PointVector< dim, double >::diagonal
static Self diagonal(Component val=1)
DGtal::PolyscopeViewer
Definition
PolyscopeViewer.h:57
DGtal::PolyscopeViewer::show
void show() override
Starts the event loop and display of elements.
Definition
PolyscopeViewer.h:73
DGtal::SimpleRandomAccessRangeFromPoint::begin
Iterator begin()
Definition
SimpleRandomAccessRangeFromPoint.h:204
DGtal::SimpleRandomAccessRangeFromPoint::end
Iterator end()
Definition
SimpleRandomAccessRangeFromPoint.h:244
DGtal::Trace::info
std::ostream & info()
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single threshold....
Definition
SimpleThresholdForegroundPredicate.h:66
DGtal::Z3i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:172
DGtal::Z3i::RealPoint
Space::RealPoint RealPoint
Definition
StdDefs.h:170
DGtal::Z3i::L2Metric
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition
StdDefs.h:199
DGtal::Z3i::Point
Space::Point Point
Definition
StdDefs.h:168
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::ClippingPlane
Clipping plane.
Definition
Display3D.h:299
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::VolWriter
Aim: Export a 3D Image using the Vol formats.
Definition
VolWriter.h:69
DGtal::WithQuantity
Attach a property to an element.
Definition
Display3D.h:331
DGtal::functors::Ceil
Functor that rounds up.
Definition
BasicFunctors.h:218
DGtal::functors::Floor
Functor that rounds down.
Definition
BasicFunctors.h:185
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
image
Image image(domain)
examples
tutorial-examples
volDTGranulo.cpp
Generated on
for DGtal by
1.18.0