DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testReverseDT.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/helpers/StdDefs.h"
34
#include "DGtal/images/ImageSelector.h"
35
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
36
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
37
#include "DGtal/geometry/volumes/distance/ReverseDistanceTransformation.h"
38
#include "DGtal/io/colormaps/HueShadeColorMap.h"
39
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
40
#include "DGtal/io/boards/Board2D.h"
41
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
43
44
using namespace
std
;
45
using namespace
DGtal
;
46
using namespace
DGtal::functors
;
47
48
49
50
template
<
typename
Image>
51
void
randomSeeds
(
Image
&input,
const
unsigned
int
nb,
const
int
value)
52
{
53
typename
Image::Point
p, low = input.lowerBound();
54
typename
Image::Vector
ext;
55
56
ext = input.extent();
57
58
for
(
unsigned
int
k = 0 ; k < nb; k++)
59
{
60
for
(
unsigned
int
dim
= 0;
dim
< Image::dimension;
dim
++)
61
{
62
p[
dim
] = rand() % (ext[
dim
]) + low[
dim
];
63
}
64
input.
setValue
(p, value);
65
}
66
}
67
68
69
71
// Functions for testing class ReverseDT.
73
77
bool
testReverseDT
()
78
{
79
unsigned
int
nbok = 0;
80
unsigned
int
nb = 0;
81
82
trace
.
beginBlock
(
"Testing Reverse DT in 2D ..."
);
83
84
Z2i::Point
a (2, 2 );
85
Z2i::Point
b ( 15, 15 );
86
87
typedef
ImageSelector< Z2i::Domain, int>::Type
Image
;
88
Image
image
(
Z2i::Domain
( a, b ));
89
90
for
(
unsigned
k = 0; k < 49; k++ )
91
{
92
a[0] = ( k / 7 ) + 5;
93
a[1] = ( k % 7 ) + 5;
94
image
.
setValue
( a, 128 );
95
}
96
97
a =
Z2i::Point
(2,2);
98
99
typedef
SimpleThresholdForegroundPredicate<Image>
Predicate;
100
Predicate aPredicate(
image
,0);
101
102
typedef
ExactPredicateLpSeparableMetric<Z2i::Space, 2>
L2Metric;
103
Z2i::Domain
dom(a,b);
104
L2Metric l2;
105
DistanceTransformation<Z2i::Space, Predicate, L2Metric >
dt
(&dom, &aPredicate, &l2);
106
107
trace
.
info
() <<
dt
<< std::endl;
108
//ReverseDT
109
trace
.
warning
()<<
"DT:"
<<endl;
110
DistanceTransformation<Z2i::Space, Predicate, L2Metric >::ConstRange::ConstIterator
it =
dt
.constRange().begin();
111
for
(
unsigned
int
y = 2; y < 16; y++)
112
{
113
for
(
unsigned
int
x = 2; x < 16; x++)
114
{
115
std::cout << (*it) <<
" "
;
116
++it;
117
}
118
std::cout << std::endl;
119
}
120
121
typedef
ReverseDistanceTransformation< DistanceTransformation<Z2i::Space, Predicate, L2Metric >
,
Z2i::L2PowerMetric
> RDT;
122
Z2i::L2PowerMetric
l2power;
123
RDT reverseDT(&dom,&
dt
,&l2power);
124
125
126
for
(
unsigned
int
j=2; j<16; j++)
127
{
128
for
(
unsigned
int
i=2; i<16; i++)
129
trace
.
info
()<< reverseDT.getPowerVector(
Z2i::Point
(i,j))[0]<<
","
<<reverseDT.getPowerVector(
Z2i::Point
(i,j))[1]<<
" "
;
130
trace
.
info
()<<std::endl;
131
}
132
133
trace
.
warning
()<<
"REDT:"
<<endl;
134
RDT::ConstRange::ConstIterator it2 = reverseDT.constRange().begin();
135
for
(
unsigned
int
y = 2; y < 16; y++)
136
{
137
for
(
unsigned
int
x = 2; x < 16; x++)
138
{
139
std::cout << (*it2) <<
" "
;
140
++it2;
141
}
142
std::cout << std::endl;
143
}
144
145
//Checking
146
bool
ok=
true
;
147
RDT::ConstRange::ConstIterator itrec = reverseDT.constRange().begin(), itend = reverseDT.constRange().end();
148
Image::ConstIterator
itinit =
image
.begin();
149
for
( ; itrec != itend; ++itrec,++itinit)
150
if
((*itrec) >= 0)
151
ok = ok & ((*itinit) == 0);
152
153
154
trace
.
info
() <<
"vector (4,7)= "
<< reverseDT.getPowerVector(
Z2i::Point
(4,7))<<std::endl;
155
nbok += (reverseDT.getPowerVector(
Z2i::Point
(4,7))==
Z2i::Point
(5,7)) ? 1 : 0;
156
nb++;
157
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
158
<<
"ok"
<< std::endl;
159
160
trace
.
info
() <<
"dist (4,7)= "
<< reverseDT.metricPtr()->exactDistanceRepresentation(
Z2i::Point
(4,7),
Z2i::Point
(5,7))<<std::endl;
161
nbok += (reverseDT.metricPtr()->exactDistanceRepresentation(
Z2i::Point
(4,7),
Z2i::Point
(5,7))==1) ? 1 : 0;
162
nb++;
163
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
164
<<
"true == true"
<< std::endl;
165
166
trace
.
info
() <<
"power (4,7)= "
<< reverseDT(
Z2i::Point
(4,7))<<std::endl;
167
nbok += (reverseDT(
Z2i::Point
(4,7))==0) ? 1 : 0;
168
nb++;
169
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
170
<<
"true == true"
<< std::endl;
171
172
173
174
175
nbok += ok ? 1 : 0;
176
nb++;
177
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
178
<<
"true == true"
<< std::endl;
179
trace
.
endBlock
();
180
181
return
nbok == nb;
182
}
183
184
bool
testReverseDTL1
()
185
{
186
unsigned
int
nbok = 0;
187
unsigned
int
nb = 0;
188
189
trace
.
beginBlock
(
"Testing Reverse DT in 2D with L1 metric ..."
);
190
191
Z2i::Point
a (2, 2 );
192
Z2i::Point
b ( 15, 15 );
193
194
typedef
ImageSelector< Z2i::Domain, unsigned int>::Type
Image
;
195
Image
image
(
Z2i::Domain
( a, b ));
196
197
for
(
unsigned
k = 0; k < 49; k++ )
198
{
199
a[0] = ( k / 7 ) + 5;
200
a[1] = ( k % 7 ) + 5;
201
image
.
setValue
( a, 128 );
202
}
203
a =
Z2i::Point
(2, 2 );
204
205
206
typedef
SimpleThresholdForegroundPredicate<Image>
Predicate;
207
Predicate aPredicate(
image
,0);
208
Z2i::Domain
dom=
image
.
domain
();
209
typedef
ExactPredicateLpSeparableMetric<Z2i::Space, 1>
L1Metric;
210
L1Metric l1;
211
DistanceTransformation<Z2i::Space, Predicate, L1Metric>
dt
(&dom, &aPredicate, &l1);
212
213
214
//ReverseDT
215
trace
.
warning
()<<
"DT:"
<<endl;
216
DistanceTransformation<Z2i::Space, Predicate, L1Metric>::ConstRange::ConstIterator
it =
dt
.constRange().begin();
217
for
(
unsigned
int
y = 2; y < 16; y++)
218
{
219
for
(
unsigned
int
x = 2; x < 16; x++)
220
{
221
std::cout << (int)(*it) <<
" "
;
222
++it;
223
}
224
std::cout << std::endl;
225
}
226
227
typedef
ReverseDistanceTransformation< DistanceTransformation<Z2i::Space, Predicate, L1Metric>
,
Z2i::L1PowerMetric
> RDT;
228
Z2i::L1PowerMetric
l1power;
229
RDT reverseDT(&dom, &
dt
, &l1power);
230
231
232
trace
.
warning
()<<
"Power"
<<std::endl;
233
for
(
unsigned
int
j=2; j<16; j++)
234
{
235
for
(
unsigned
int
i=2; i<16; i++)
236
trace
.
info
()<< reverseDT.getPowerVector(
Z2i::Point
(i,j))[0]<<
","
<<reverseDT.getPowerVector(
Z2i::Point
(i,j))[1]<<
" "
;
237
trace
.
info
()<<std::endl;
238
}
239
240
trace
.
warning
()<<
"REDT:"
<<endl;
241
RDT::ConstRange::ConstIterator it2 = reverseDT.constRange().begin();
242
for
(
unsigned
int
y = 2; y < 16; y++)
243
{
244
for
(
unsigned
int
x = 2; x < 16; x++)
245
{
246
std::cout << (int)(*it2) <<
" "
;
247
++it2;
248
}
249
std::cout << std::endl;
250
}
251
252
//Checking
253
bool
ok=
true
;
254
RDT::ConstRange::ConstIterator itrec = reverseDT.constRange().begin(), itend = reverseDT.constRange().end();
255
Image::ConstIterator
itinit =
image
.begin();
256
for
( ; itrec != itend; ++itrec,++itinit)
257
if
((*itrec) >= 0)
258
ok = ok & ((*itinit) == 0);
259
260
nbok += ok ? 1 : 0;
261
nb++;
262
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
263
<<
"true == true"
<< std::endl;
264
trace
.
endBlock
();
265
return
nbok == nb;
266
}
267
269
// Standard services - public :
270
271
int
main
(
int
argc,
char
** argv )
272
{
273
trace
.
beginBlock
(
"Testing class ReverseDT"
);
274
trace
.
info
() <<
"Args:"
;
275
for
(
int
i = 0; i < argc; ++i )
276
trace
.
info
() <<
" "
<< argv[ i ];
277
trace
.
info
() << endl;
278
279
bool
res =
testReverseDT
()
280
&&
testReverseDTL1
();
// && ... other tests
281
282
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
283
trace
.
endBlock
();
284
return
res ? 0 : 1;
285
}
286
// //
DGtal::DefaultConstImageRange< Self >::ConstIterator
ConstIteratorAdapter< typename Domain::ConstIterator, Self, Value > ConstIterator
Definition
DefaultConstImageRange.h:91
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition
ExactPredicateLpSeparableMetric.h:88
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
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::ReverseDistanceTransformation
Aim: Implementation of the linear in time reverse distance transformation for separable metrics.
Definition
ReverseDistanceTransformation.h:95
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::warning
std::ostream & warning()
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
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
dt
float dt
Definition
dgtalCalculus-geodesic.cpp:63
DGtal::Z2i::L2PowerMetric
ExactPredicateLpPowerSeparableMetric< Space, 2 > L2PowerMetric
Definition
StdDefs.h:120
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal::Z2i::L1PowerMetric
ExactPredicateLpPowerSeparableMetric< Space, 1 > L1PowerMetric
Definition
StdDefs.h:121
DGtal::functors
functors namespace gathers all DGtal functors.
Definition
BasicBoolFunctors.h:49
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::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
testReverseDTL1
bool testReverseDTL1()
Definition
testReverseDT.cpp:184
testReverseDT
bool testReverseDT()
Definition
testReverseDT.cpp:77
image
Image image(domain)
tests
geometry
volumes
distance
testReverseDT.cpp
Generated on
for DGtal by
1.18.0