33#include "DGtal/base/Common.h"
35#include "DGtal/kernel/SpaceND.h"
36#include "DGtal/kernel/domains/HyperRectDomain.h"
37#include "DGtal/images/ImageSelector.h"
38#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
39#include "DGtal/geometry/volumes/distance/VoronoiMap.h"
40#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
41#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
42#include "DGtal/io/colormaps/HueShadeColorMap.h"
43#include "DGtal/io/colormaps/GrayscaleColorMap.h"
44#include "DGtal/shapes/Shapes.h"
45#include "DGtal/helpers/StdDefs.h"
46#include "DGtal/shapes/ShapeFactory.h"
47#include "DGtal/io/boards/Board2D.h"
48#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
59template<
typename Image>
62 typename Image::Point p, low = input.domain().lowerBound(), up = input.domain().upperBound();
65 for (
Dimension i = 0; i < Image::Domain::dimension; i++)
66 ext[i] = up[i] - low[i] + 1;
69 for (
unsigned int k = 0 ; k < nb; k++)
71 for (
unsigned int dim = 0;
dim < Image::dimension;
dim++)
75 input.setValue(p, value);
92 typedef TSpace::Point
Point;
100 for (
unsigned k = 0; k < 49; k++ )
102 a[0] = ( k / 7 ) + 5;
103 a[1] = ( k % 7 ) + 5;
104 image.setValue ( a, 128 );
109 Predicate aPredicate(image,0);
120 board.
saveSVG (
"image-preDT.svg" );
122 std::copy ( image.begin(),
124 std::ostream_iterator<unsigned int> ( std::cout,
" " ) );
127 for(
int i=2;i<=15;++i)
129 for(
int j=2;j<=15;++j)
141 for (; it != itend; ++it)
143 std::cout << (*it) <<
" ";
145 std::cout << std::endl;
148 for(
int i=2;i<=15;++i)
150 for(
int j=2;j<=15;++j)
157 for(
int i=2;i<=15;++i)
159 for(
int j=2;j<=15;++j)
174 for(
int i=2;i<=15;++i)
176 for(
int j=2;j<=15;++j)
179 if (p !=
dt.getVoronoiSite(
Point(i,j)))
191 board.
saveSVG (
"image-postDT.svg" );
203 unsigned int nbok = 0;
209 typedef TSpace::Point
Point;
212 Point a ( -10, -10 );
217 for(
int y=-10; y<=10;y++)
218 for(
int x=-10; x<=10;x++)
220 if ((abs(x)<7) && (abs(y)<5))
221 image.setValue(
Point(x,y),1);
223 image.setValue(
Point(x,y),0);
227 Predicate aPredicate(image,0);
234 board.
saveSVG (
"image-preDT-neg.svg" );
237 for(
int y=-10; y<=10;y++)
239 for(
int x=-10; x<=10;x++)
241 std::cout<<image(
Point(x,y))<<
" ";
243 std::cout<<std::endl;
252 itend =
dt.constRange().end();
257 for(
int y=-10; y<=10;y++)
259 for(
int x=-10; x<=10;x++)
261 std::cout<<
dt(
Point(x,y))<<
" ";
263 std::cout<<std::endl;
275 board.
saveSVG (
"image-postDT-neg.svg" );
289 unsigned int nbok = 0;
315 L1DT dt1(&
domain,&aSet, &l1);
317 L2DT::Value maxv = 0;
318 for ( L2DT::ConstRange::ConstIterator it =
dt.constRange().begin(), itend =
dt.constRange().end();
324 board.
saveSVG (
"image-DTSet.svg" );
328 for ( L1DT::ConstRange::ConstIterator it = dt1.constRange().begin(), itend = dt1.constRange().end();
334 board.
saveSVG (
"image-DTSet-l1.svg" );
346 unsigned int nbok = 0;
349 trace.
beginBlock (
"Testing DT computation with Infinity values at the first step" );
352 typedef TSpace::Point
Point;
357 Point b ( 128, 128 );
362 for (
Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
369 Predicate aPredicate(image,0);
379 board.
saveSVG (
"image-preDT-border.svg" );
387 for (
unsigned int y = 0; y < 33; y++)
389 for (
unsigned int x = 0; x < 33; x++)
391 std::cout << std::setw(4) << (*it) <<
" ";
394 std::cout << std::endl;
402 board.
saveSVG (
"image-postDT-border.svg" );
419 unsigned int nbok = 0;
425 typedef TSpace::Point
Point;
428 Point b ( 15, 15, 15 );
435 itend = dom.
end(); it != itend; ++it)
437 if ( ((*it) - c).norm() < 7)
438 image.setValue ( *it, 128 );
442 Predicate aPredicate(image,0);
449 for (
unsigned int y = 0; y < 16; y++)
451 for (
unsigned int x = 0; x < 16; x++)
454 std::cout <<
dt(p) <<
" ";
456 std::cout << std::endl;
470 unsigned int nbok = 0;
473 trace.
beginBlock (
"Testing DT computation with Infinity values at the first step" );
476 typedef TSpace::Point
Point;
481 Point b ( 128, 128 );
487 for (
Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
494 Predicate aPredicate(image,0);
501 DT2 dt2(&dom, &aPredicate, &l2);
502 DT2 dt2_periodic( &dom, &aPredicate, &l2, {
true,
true} );
512 DT1 dt1(&dom,&aPredicate,&l1);
513 DT1 dt1_periodic( &dom, &aPredicate, &l1, {
true,
true} );
522 for (
unsigned int y = 0; y < 16; y++)
524 for (
unsigned int x = 0; x < 16; x++)
527 std::cout << std::setw(4) << dt2(p) <<
" ";
529 std::cout << std::endl;
537 board.
saveSVG (
"image-DT-l2.svg" );
541 board.
saveSVG (
"image-DT-l2-periodic.svg" );
550 itend = dt1.constRange().end();
557 trace.
info()<<
"Exporting to SVG L1"<<endl;
560 board.
saveSVG (
"image-DT-l1.svg" );
564 board.
saveSVG (
"image-DT-l1-periodic.svg" );
574template <
typename Space,
int norm>
586 Point low=Point::diagonal(0),
587 up=Point::diagonal(size);
592 for(
unsigned int i = 0; i<nb; ++i)
596 p[
dim] = rand() % size;
600 trace.
info()<<
"Testing metrics "<<MetricEx()<<
" "<<MetricInex(norm)<<std::endl;
602 trace.
info()<<
"Inserting "<<set.size() <<
" points."<<std::endl;
605 NegPredicate negPred(set);
610 MetricInex metricInex(norm);
611 DTEx dtex(&
domain, &negPred, &metricEx);
612 DTIn dtinex(&
domain, &negPred, &metricInex);
615 typename DTEx::ConstRange::ConstIterator it=dtex.constRange().begin(), itend=dtex.constRange().end();
616 typename DTIn::ConstRange::ConstIterator it2 = dtinex.constRange().begin();
617 for( ; it != itend; ++it, ++it2)
618 MSE += ((*it) - (*it2))*((*it) - (*it2));
628int main (
int argc,
char** argv ){
632 for (
int i = 0; i < argc; ++i )
648 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Model of the concept StarShaped represents any accelerated flower in the plane.
RealPoint getLowerBound() const
RealPoint getUpperBound() const
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A container class for storing sets of digital points within some given domain.
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
const ConstIterator & end() const
std::vector< Value >::iterator Iterator
Aim: implements association bewteen points lying in a digital domain and values.
Aim: implements separable l_p metrics with approximated predicates.
static void euclideanShaper(TDigitalSet &aSet, const TShapeFunctor &aFunctor, const double h=1.0)
static const Dimension dimension
static constants to store the dimension.
void beginBlock(const std::string &keyword="")
Aim: Implementation of the linear in time Voronoi map construction.
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
DGtal::uint32_t Dimension
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
Aim: The predicate returns true when the point predicate given at construction return false....
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain