DGtal 1.4.0
Loading...
Searching...
No Matches
testImagesSetsUtilities.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/images/imagesSetsUtils/ImageFromSet.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/kernel/sets/DigitalSetInserter.h"
#include "DGtal/images/ImageHelper.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigTest.h"
Include dependency graph for testImagesSetsUtilities.cpp:

Go to the source code of this file.

Functions

bool testImageFromSet ()
 
bool testSetFromImage ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/03/26
Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/15

Functions for testing ImageHelper functions.

This file is part of the DGtal library.

Definition in file testImagesSetsUtilities.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 229 of file testImagesSetsUtilities.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testImageFromSet()
bool testSetFromImage()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testImageFromSet(), testSetFromImage(), and DGtal::trace.

◆ testImageFromSet()

bool testImageFromSet ( )

Example of a test. To be completed.

Definition at line 79 of file testImagesSetsUtilities.cpp.

80{
81
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}
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
ConstRange constRange() const
Definition Image.h:203
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
void imageFromFunctor(I &aImg, const F &aFun)
void imageFromImage(I1 &aImg1, const I2 &aImg2)
void imageFromRangeAndValue(const It &itb, const It &ite, Im &aImg, const typename Im::Value &aValue=0)
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::begin(), DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::constRange(), DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::end(), DGtal::Trace::endBlock(), DGtal::imageFromFunctor(), DGtal::imageFromImage(), DGtal::imageFromRangeAndValue(), DGtal::Trace::info(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), and DGtal::trace.

Referenced by main().

◆ testSetFromImage()

bool testSetFromImage ( )

Definition at line 135 of file testImagesSetsUtilities.cpp.

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
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 };
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}
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set....
void setFromImage(const I &aImg, const O &ito, const typename I::Value &aThreshold=0)
void setFromPointsRangeAndPredicate(const I &itb, const I &ite, const O &ito, const P &aPred)
useful functions
Aim: The predicate returns true when the predicate returns true for the value assigned to a given poi...

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::find(), DGtal::Trace::info(), DGtal::setFromImage(), DGtal::setFromPointsRangeAndPredicate(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::size(), DGtal::HyperRectDomain< TSpace >::size(), and DGtal::trace.

Referenced by main().