DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testImagesSetsUtilities.cpp
Go to the documentation of this file.
1
16
34
36
#include <iostream>
37
#include "DGtal/base/Common.h"
38
39
#include "DGtal/images/imagesSetsUtils/ImageFromSet.h"
40
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
41
42
#include "DGtal/kernel/sets/DigitalSetInserter.h"
43
#include "DGtal/images/ImageHelper.h"
44
45
#include "DGtal/images/ImageContainerBySTLMap.h"
46
#include "DGtal/images/ImageContainerBySTLVector.h"
47
#include "DGtal/images/ImageSelector.h"
48
49
#include "DGtal/helpers/StdDefs.h"
50
51
#include "ConfigTest.h"
52
54
55
using namespace
std
;
56
using namespace
DGtal
;
57
using namespace
Z2i
;
58
60
// Functions for testing ImageHelper functions.
62
63
template
<
typename
P>
64
struct
Norm1
65
{
66
typedef
P
Point
;
67
typedef
typename
P::Coordinate
Value
;
68
69
Value
operator()
(
const
Point
& p)
70
{
71
return
p.norm1();
72
}
73
};
74
79
bool
testImageFromSet
()
80
{
81
82
typedef
ImageContainerBySTLVector<Domain,int>
Image
;
83
84
unsigned
int
nbok = 0;
85
unsigned
int
nb = 0;
86
87
trace
.
beginBlock
(
"Testing ImageFromSet ..."
);
88
89
Point
a(0,0);
90
Point
b(23,435);
91
Point
c(12,12);
92
93
Domain
d(a,b);
94
DigitalSet
aSet(d);
95
aSet.
insert
(c);
96
97
Image
image
(d);
98
//assign to the points belonging to aSet the value 128
99
imageFromRangeAndValue
(aSet,
image
, 128);
100
//ie. the value of c is 128 but the value of a remains 0
101
nbok += ( (
image
(c) == 128)&&(
image
(a) == 0) ) ? 1 : 0;
102
nb++;
103
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
104
105
Image
image2(d);
106
Norm1<Point>
n;
107
//fill image2 from n
108
imageFromFunctor
(image2, n);
109
nbok += ( (image2(c) == (int)c.norm1())
110
&&(image2(a) == (int)a.norm1())
111
&&(image2(b) == (int)b.norm1()) )? 1 : 0;
112
nb++;
113
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
114
115
Image
image3 =
image
;
116
//fill image3 from image2
117
imageFromImage
(image3,
const_cast<
Image
const&
>
(image2));
118
//image2 and image3 should be equal,
119
//but both different from image
120
Image::ConstRange
rimg =
image
.
constRange
();
121
Image::ConstRange
rimg2 = image2.
constRange
();
122
Image::ConstRange
rimg3 = image3.
constRange
();
123
bool
flag2 = std::equal(rimg.
begin
(), rimg.
end
(), rimg2.
begin
());
124
bool
flag3 = std::equal(rimg.
begin
(), rimg.
end
(), rimg3.
begin
());
125
bool
flag23 = std::equal(rimg2.
begin
(), rimg2.
end
(), rimg3.
begin
());
126
nbok += ( (!flag2) && (!flag3) && flag23 )?1:0;
127
nb++;
128
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
129
130
trace
.
endBlock
();
131
132
return
nbok == nb;
133
}
134
135
bool
testSetFromImage
()
136
{
137
unsigned
int
nbok = 0;
138
unsigned
int
nb = 0;
139
140
trace
.
beginBlock
(
"Testing SetFromImage ..."
);
141
142
//some points
143
Point
a(0,0);
144
Point
b(3,3);
145
Point
p(1,1);
146
Point
q(2,2);
147
Point
r(1,2);
148
149
//image construction
150
typedef
ImageContainerBySTLMap<Domain,int>
Image
;
151
Domain
d(a,b);
152
Image
image
(d,1);
153
image
.
setValue
(p,127);
154
image
.
setValue
(q,128);
155
image
.
setValue
(r,10);
156
157
//image content
158
Image::ConstRange
range =
image
.
constRange
();
159
std::copy(range.
begin
(), range.
end
(), ostream_iterator<Image::Value>(cout,
" "
) );
160
cout << endl;
161
162
//set tests
163
164
DigitalSet
aSet(d);
165
DigitalSetInserter<DigitalSet>
inserter(aSet);
166
//all points whose value <= 126
167
setFromImage
(
image
, inserter, 126 );
168
//ie, all points except p and q
169
nbok += ( (aSet.
find
(p) == aSet.
end
())
170
&&(aSet.
find
(q) == aSet.
end
())
171
&&(aSet.
size
()==(d.size()-2)) ) ? 1 : 0;
172
nb++;
173
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
174
175
DigitalSet
aSet2(d);
176
DigitalSetInserter<DigitalSet>
inserter2(aSet2);
177
//all points whose value <= 127
178
setFromImage
(
image
, inserter2, 127 );
179
//ie, all points except q
180
nbok += ( (aSet2.
find
(q) == aSet2.
end
())
181
&&(aSet2.
size
()==(d.size()-1)) ) ? 1 : 0;
182
nb++;
183
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
184
185
DigitalSet
aSet3(d);
186
DigitalSetInserter<DigitalSet>
inserter3(aSet3);
187
//all points whose value <= 128
188
setFromImage
(
image
, inserter3, 128 );
189
//ie, all points
190
nbok += ( aSet3.
size
()==d.size() ) ? 1 : 0;
191
nb++;
192
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
193
194
DigitalSet
aSet4(d);
195
DigitalSetInserter<DigitalSet>
inserter4(aSet4);
196
//all points whose value is between 2 and 100
197
setFromImage
(
image
, inserter4, 2, 100 );
198
//ie, only point r
199
nbok += ( (aSet4.
find
(r)!=aSet4.
end
())&&(aSet4.
size
()==1) ) ? 1 : 0;
200
nb++;
201
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
202
203
DigitalSet
aSet5(d);
204
DigitalSetInserter<DigitalSet>
inserter5(aSet5);
205
//predicate construction
206
using
ValuePredicate = std::function<bool(
const
Image::Value
&)>;
207
ValuePredicate equalTo1 = [](
const
Image::Value
& v)
208
{
209
return
v == 1;
210
};
211
functors::PointFunctorPredicate<Image, ValuePredicate>
pred(
image
, equalTo1);
212
//all points whose value is 1
213
setFromPointsRangeAndPredicate
( d.begin(), d.end(), inserter5, pred );
214
//ie all points except p, q, and r
215
nbok += ( (aSet5.
find
(p) == aSet5.
end
())
216
&&(aSet5.
find
(q) == aSet5.
end
())
217
&&(aSet5.
find
(r) == aSet5.
end
())
218
&&(aSet5.
size
()==(d.size()-3)) ) ? 1 : 0;
219
nb++;
220
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
221
222
223
return
nbok == nb;
224
}
225
227
// Standard services - public :
228
229
int
main
(
int
argc,
char
** argv )
230
{
231
trace
.
beginBlock
(
"Testing class ImageHelper functions"
);
232
trace
.
info
() <<
"Args:"
;
233
for
(
int
i = 0; i < argc; ++i )
234
trace
.
info
() <<
" "
<< argv[ i ];
235
trace
.
info
() << endl;
236
237
bool
res =
testImageFromSet
() &&
testSetFromImage
();
238
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
239
trace
.
endBlock
();
240
return
res ? 0 : 1;
241
}
242
// //
DGtal::DigitalSetByAssociativeContainer::end
ConstIterator end() const
DGtal::DigitalSetByAssociativeContainer::size
Size size() const
DGtal::DigitalSetByAssociativeContainer::insert
void insert(const Point &p)
DGtal::DigitalSetByAssociativeContainer::find
ConstIterator find(const Point &p) const
DGtal::DigitalSetInserter
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set....
Definition
DigitalSetInserter.h:66
DGtal::ImageContainerBySTLMap
Definition
ImageContainerBySTLMap.h:98
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition
ImageContainerBySTLVector.h:274
DGtal::ImageContainerBySTLVector< Domain, Value >::Value
Value Value
Definition
ImageContainerBySTLVector.h:153
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::constRange
ConstRange constRange() const
Definition
Image.h:203
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
DGtal::SimpleRandomAccessConstRangeFromPoint::begin
ConstIterator begin() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:192
DGtal::SimpleRandomAccessConstRangeFromPoint::end
ConstIterator end() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:212
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition
StdDefs.h:100
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::setFromImage
void setFromImage(const I &aImg, const O &ito, const typename I::Value &aThreshold=0)
DGtal::imageFromFunctor
void imageFromFunctor(I &aImg, const F &aFun)
DGtal::trace
Trace trace
DGtal::imageFromImage
void imageFromImage(I1 &aImg1, const I2 &aImg2)
DGtal::imageFromRangeAndValue
void imageFromRangeAndValue(const It &itb, const It &ite, Im &aImg, const typename Im::Value &aValue=0)
DGtal::setFromPointsRangeAndPredicate
void setFromPointsRangeAndPredicate(const I &itb, const I &ite, const O &ito, const P &aPred)
useful functions
std
STL namespace.
DGtal::functors::PointFunctorPredicate
Aim: The predicate returns true when the predicate returns true for the value assigned to a given poi...
Definition
BasicPointPredicates.h:371
Norm1
Definition
testImagesSetsUtilities.cpp:65
Norm1::Value
P::Coordinate Value
Definition
testImagesSetsUtilities.cpp:67
Norm1::operator()
Value operator()(const Point &p)
Definition
testImagesSetsUtilities.cpp:69
Norm1::Point
P Point
Definition
testImagesSetsUtilities.cpp:66
testImageFromSet
bool testImageFromSet()
Definition
testImagesSetsUtilities.cpp:79
testSetFromImage
bool testSetFromImage()
Definition
testImagesSetsUtilities.cpp:135
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
image
Image image(domain)
tests
kernel
testImagesSetsUtilities.cpp
Generated on
for DGtal by
1.18.0