DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
distancetransform3D.cpp
Go to the documentation of this file.
1
16
27
37
38
40
#include <iostream>
41
42
#include "DGtal/base/Common.h"
43
#include "DGtal/kernel/SpaceND.h"
44
#include "DGtal/kernel/domains/HyperRectDomain.h"
45
#include "DGtal/images/ImageSelector.h"
46
#include "DGtal/io/readers/VolReader.h"
47
48
#include "DGtal/io/Color.h"
49
#include "DGtal/io/colormaps/GradientColorMap.h"
50
#include "DGtal/io/viewers/PolyscopeViewer.h"
51
52
#include "DGtal/kernel/SpaceND.h"
53
#include "DGtal/kernel/domains/HyperRectDomain.h"
54
#include "DGtal/images/ImageSelector.h"
55
56
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
57
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
58
#include "DGtal/helpers/StdDefs.h"
59
60
#include "ConfigExamples.h"
61
62
#include "DGtal/helpers/StdDefs.h"
63
65
66
using namespace
std
;
67
using namespace
DGtal
;
68
70
71
79
template
<
typename
Image>
80
void
randomSeeds
(
Image
&
image
,
const
unsigned
int
nb,
const
int
value)
81
{
82
typename
Image::Point
p, low =
image
.
domain
().
lowerBound
();
83
typename
Image::Vector
ext;
84
srand
( time(NULL) );
85
86
ext =
image
.extent();
87
88
for
(
unsigned
int
k = 0 ; k < nb; k++)
89
{
90
for
(
unsigned
int
dim
= 0;
dim
< Image::dimension;
dim
++)
91
p[
dim
] = rand() % (ext[
dim
]) + low[
dim
];
92
93
image
.
setValue
(p, value);
94
}
95
}
96
97
using namespace
DGtal
;
98
99
int
main
()
100
{
101
102
std::string inputFilename = examplesPath +
"samples/Al.100.vol"
;
103
104
//------------
105
PolyscopeViewer<>
viewer;
106
107
108
109
//Default image selector = STLVector
110
typedef
ImageSelector<Z3i::Domain, unsigned char>::Type
Image
;
111
Image
image
=
VolReader<Image>::importVol
( inputFilename );
112
Z3i::Domain
domain
=
image
.
domain
();
113
114
115
Image
imageSeeds (
domain
);
116
for
(
Image::Iterator
it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
117
(*it)=1;
118
Z3i::Point
p0(10,10,10);
119
//imageSeeds.setValue(p0, 0 );
120
randomSeeds
(imageSeeds, 70, 0);
121
122
123
//Distance transformation computation
124
typedef
functors::SimpleThresholdForegroundPredicate<Image>
Predicate;
125
Predicate aPredicate(imageSeeds,0);
126
127
typedef
DistanceTransformation<Z3i::Space,Predicate, Z3i::L2Metric>
DTL2;
128
DTL2 dtL2(&
domain
, &aPredicate, &Z3i::l2Metric);
129
130
unsigned
int
min = 0;
131
unsigned
int
max
= 0;
132
for
(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
133
itend=dtL2.constRange().end();
134
it!=itend;
135
++it)
136
{
137
if
( (*it) < min )
138
min=(*it);
139
if
( (*it) >
max
)
140
max
=(*it);
141
}
142
143
144
GradientColorMap<long>
gradient( 0,30);
145
gradient.
addColor
(
Color::Red
);
146
gradient.
addColor
(
Color::Yellow
);
147
gradient.
addColor
(
Color::Green
);
148
gradient.
addColor
(
Color::Cyan
);
149
gradient.
addColor
(
Color::Blue
);
150
gradient.
addColor
(
Color::Magenta
);
151
gradient.
addColor
(
Color::Red
);
152
153
for
(
Z3i::Domain::ConstIterator
it =
domain
.begin(), itend=
domain
.end();
154
it!=itend;
155
++it){
156
157
// Could be better with "WithQuantity", but there is a filter that is
158
// not easy to emulate with colormaps
159
double
valDist= dtL2( (*it) );
160
Color
c= gradient(valDist);
161
162
if
(dtL2(*it)<=30 &&
image
(*it)>0){
163
viewer <<
Color
((
float
)(c.
red
()),
164
(
float
)(c.
green
()),
165
(
float
)(c.
blue
(),205));
166
viewer << *it ;
167
}
168
}
169
170
viewer.
show
();
171
return
0;
172
}
173
// //
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition
Color.h:77
DGtal::Color::green
void green(const unsigned char aGreenValue)
DGtal::Color::Red
static const Color Red
Definition
Color.h:425
DGtal::Color::Color
Color()
Definition
Color.h:139
DGtal::Color::Blue
static const Color Blue
Definition
Color.h:428
DGtal::Color::red
void red(const unsigned char aRedValue)
DGtal::Color::Yellow
static const Color Yellow
Definition
Color.h:431
DGtal::Color::Cyan
static const Color Cyan
Definition
Color.h:429
DGtal::Color::Green
static const Color Green
Definition
Color.h:426
DGtal::Color::blue
void blue(const unsigned char aBlueValue)
DGtal::Color::Magenta
static const Color Magenta
Definition
Color.h:430
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
GradientColorMap.h:120
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition
ImageContainerBySTLVector.h:264
DGtal::ImageContainerBySTLVector< Domain, Value >::Vector
Domain::Vector Vector
Definition
ImageContainerBySTLVector.h:139
DGtal::ImageContainerBySTLVector< Domain, Value >::Point
Domain::Point Point
Definition
ImageContainerBySTLVector.h:138
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::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
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::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::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
std
STL namespace.
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
max
int max(int a, int b)
Definition
testArithmeticalDSS.cpp:1108
srand
srand(0)
randomSeeds
void randomSeeds(Image &input, const unsigned int nb, const int value)
Definition
testDistanceTransformation.cpp:60
dim
#define dim
Definition
testImageContainerByHashTree.cpp:40
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
image
Image image(domain)
examples
geometry
volumes
distance
distancetransform3D.cpp
Generated on
for DGtal by
1.18.0