DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
distancetransform2D.cpp
Go to the documentation of this file.
1
16
33
34
42
43
45
#include <iostream>
46
#include <iomanip>
47
#include "DGtal/base/Common.h"
48
#include "DGtal/helpers/StdDefs.h"
49
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
50
#include "DGtal/io/colormaps/HueShadeColorMap.h"
51
#include "DGtal/io/colormaps/TickedColorMap.h"
52
#include "DGtal/io/colormaps/GradientColorMap.h"
53
#include "DGtal/io/boards/Board2D.h"
54
#include "DGtal/images/ImageSelector.h"
55
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
56
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
58
59
using namespace
std
;
60
using namespace
DGtal
;
61
63
71
template
<
typename
Image>
72
void
randomSeeds
(
Image
&
image
,
const
unsigned
int
nb,
const
int
value)
73
{
74
typename
Image::Point
p, low =
image
.
domain
().
lowerBound
();
75
typename
Image::Vector
ext;
76
77
ext =
image
.extent();
78
79
for
(
unsigned
int
k = 0 ; k < nb; k++)
80
{
81
for
(
unsigned
int
dim
= 0;
dim
< Image::dimension;
dim
++)
82
p[
dim
] = rand() % (ext[
dim
]) + low[
dim
];
83
84
image
.
setValue
(p, value);
85
}
86
}
87
88
int
main
()
89
{
90
trace
.
beginBlock
(
"Example distancetransform2D"
);
91
93
Z2i::Point
a ( 0, 0 );
94
Z2i::Point
b ( 127, 127);
95
96
//Input image with unsigned char values
97
typedef
ImageSelector<Z2i::Domain, unsigned int>::Type
Image
;
98
Image
image
(
Z2i::Domain
(a, b ));
99
100
//We fill the image with the 128 value
101
for
(
Image::Iterator
it =
image
.begin(), itend =
image
.end();it != itend; ++it)
102
(*it)=128;
103
//We generate 16 seeds with 0 values.
104
randomSeeds
(
image
,16,0);
106
107
//Input shape output
108
typedef
GrayscaleColorMap<Image::Value>
Gray;
109
Board2D
board;
110
board.
setUnit
(
LibBoard::Board::UCentimeter
);
111
Display2DFactory::drawImage<Gray>
(board,
image
, (
unsigned
int
)0, (
unsigned
int
)129);
112
board.
saveSVG
(
"inputShape.svg"
);
113
115
//Point Predicate from random seed image
116
typedef
functors::SimpleThresholdForegroundPredicate<Image>
PointPredicate;
117
PointPredicate predicate(
image
,0);
119
121
typedef
DistanceTransformation<Z2i::Space, PointPredicate, Z2i::L2Metric>
DTL2;
122
typedef
DistanceTransformation<Z2i::Space, PointPredicate, Z2i::L1Metric>
DTL1;
123
124
125
DTL2 dtL2(
image
.
domain
(), predicate, Z2i::l2Metric);
126
DTL1 dtL1(
image
.
domain
(), predicate, Z2i::l1Metric);
128
129
130
DTL2::Value maxv2=0;
131
//We compute the maximum DT value on the L2 map
132
for
( DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(), itend = dtL2.constRange().end();it != itend; ++it)
133
if
( (*it) > maxv2) maxv2 = (*it);
134
135
DTL1::Value maxv1=0;
136
//We compute the maximum DT value on the L1 map
137
for
( DTL1::ConstRange::ConstIterator it = dtL1.constRange().begin(), itend = dtL1.constRange().end();it != itend; ++it)
138
if
( (*it) > maxv1) maxv1 = (*it);
139
141
//Colormap used for the SVG output
142
typedef
HueShadeColorMap<DTL2::Value, 2>
HueTwice;
144
145
146
147
148
trace
.
warning
() << dtL2 <<
" maxValue= "
<<maxv2<< endl;
149
board.
clear
();
150
Display2DFactory::drawImage<HueTwice>
(board, dtL2, 0.0, maxv2 + 1);
151
board.
saveSVG
(
"example-DT-L2.svg"
);
152
153
trace
.
warning
() << dtL1 <<
" maxValue= "
<<maxv1<< endl;
154
board.
clear
();
155
Display2DFactory::drawImage<HueTwice>
(board, dtL1, 0.0, maxv1 + 1);
156
board.
saveSVG
(
"example-DT-L1.svg"
);
157
158
//Explicit export with ticked colormap
159
//We compute the maximum DT value on the L2 map
160
board.
clear
();
161
TickedColorMap<double, GradientColorMap<double>
> ticked(0.0,maxv2,
Color::White
);
162
ticked.
addRegularTicks
(5, 0.5);
163
ticked.
finalize
();
164
ticked.
colormap
()->addColor(
Color::Red
);
165
ticked.
colormap
()->addColor(
Color::Black
);
166
for
( DTL2::Domain::ConstIterator it = dtL2.domain().begin(), itend = dtL2.domain().end();it != itend; ++it)
167
{
168
board<<
CustomStyle
((*it).className(),
new
CustomColors
(ticked(dtL2(*it)),ticked(dtL2(*it))));
169
board << *it;
170
}
171
board.
saveSVG
(
"example-DT-L2-ticked.svg"
);
172
173
trace
.
endBlock
();
174
return
0;
175
}
176
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Red
static const Color Red
Definition
Color.h:425
DGtal::Color::Black
static const Color Black
Definition
Color.h:422
DGtal::Color::White
static const Color White
Definition
Color.h:424
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::GrayscaleColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Definition
GrayscaleColorMap.h:94
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
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::TickedColorMap
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
Definition
TickedColorMap.h:79
DGtal::TickedColorMap::addRegularTicks
void addRegularTicks(const unsigned int nbTicks, const Value thickness)
DGtal::TickedColorMap::colormap
ColorMap * colormap() const
Definition
TickedColorMap.h:181
DGtal::TickedColorMap::finalize
void finalize()
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::warning
std::ostream & warning()
DGtal::Trace::endBlock
double endBlock()
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single threshold....
Definition
SimpleThresholdForegroundPredicate.h:66
LibBoard::Board::UCentimeter
@ UCentimeter
Definition
Board.h:43
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition
Board.cpp:151
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition
Board.cpp:239
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition
Board2D.h:279
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
DGtal::Display2DFactory::drawImage
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
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
image
Image image(domain)
examples
geometry
volumes
distance
distancetransform2D.cpp
Generated on
for DGtal by
1.18.0