Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
distancetransform3D.cpp
Go to the documentation of this file.
1
16
27
37
38
40#include <iostream>
41
42#include "DGtal/base/Common.h"
43#include "DGtal/kernel/SpaceND.h"
44#include "DGtal/kernel/domains/HyperRectDomain.h"
45#include "DGtal/images/ImageSelector.h"
46#include "DGtal/io/readers/VolReader.h"
47
48#include "DGtal/io/Color.h"
49#include "DGtal/io/colormaps/GradientColorMap.h"
50#include "DGtal/io/viewers/PolyscopeViewer.h"
51
52#include "DGtal/kernel/SpaceND.h"
53#include "DGtal/kernel/domains/HyperRectDomain.h"
54#include "DGtal/images/ImageSelector.h"
55
56#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
57#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
58#include "DGtal/helpers/StdDefs.h"
59
60#include "ConfigExamples.h"
61
62#include "DGtal/helpers/StdDefs.h"
63
65
66using namespace std;
67using namespace DGtal;
68
70
71
79template<typename Image>
80void randomSeeds(Image &image, const unsigned int nb, const int value)
81{
82 typename Image::Point p, low = image.domain().lowerBound();
83 typename Image::Vector ext;
84 srand ( time(NULL) );
85
86 ext = image.extent();
87
88 for (unsigned int k = 0 ; k < nb; k++)
89 {
90 for (unsigned int dim = 0; dim < Image::dimension; dim++)
91 p[dim] = rand() % (ext[dim]) + low[dim];
92
93 image.setValue(p, value);
94 }
95}
96
97using namespace DGtal;
98
99int main( int argc, char** argv )
100{
101
102 std::string inputFilename = examplesPath + "samples/Al.100.vol";
103
104 //------------
105 PolyscopeViewer<> viewer;
106
107
108
109 //Default image selector = STLVector
111 Image image = VolReader<Image>::importVol( inputFilename );
112 Z3i::Domain domain = image.domain();
113
114
115 Image imageSeeds ( domain);
116 for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
117 (*it)=1;
118 Z3i::Point p0(10,10,10);
119 //imageSeeds.setValue(p0, 0 );
120 randomSeeds(imageSeeds, 70, 0);
121
122
123 //Distance transformation computation
125 Predicate aPredicate(imageSeeds,0);
126
128 DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
129
130 unsigned int min = 0;
131 unsigned int max = 0;
132 for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
133 itend=dtL2.constRange().end();
134 it!=itend;
135 ++it)
136 {
137 if( (*it) < min )
138 min=(*it);
139 if( (*it) > max )
140 max=(*it);
141 }
142
143
144 GradientColorMap<long> gradient( 0,30);
145 gradient.addColor(Color::Red);
146 gradient.addColor(Color::Yellow);
147 gradient.addColor(Color::Green);
148 gradient.addColor(Color::Cyan);
149 gradient.addColor(Color::Blue);
150 gradient.addColor(Color::Magenta);
151 gradient.addColor(Color::Red);
152
153 for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
154 it!=itend;
155 ++it){
156
157 // Could be better with "WithQuantity", but there is a filter that is
158 // not easy to emulate with colormaps
159 double valDist= dtL2( (*it) );
160 Color c= gradient(valDist);
161
162 if(dtL2(*it)<=30 && image(*it)>0){
163 viewer << Color((float)(c.red()),
164 (float)(c.green()),
165 (float)(c.blue(),205));
166 viewer << *it ;
167 }
168 }
169
170 viewer.show();
171 return 0;
172}
173// //
175
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void green(const unsigned char aGreenValue)
static const Color Red
Definition Color.h:425
static const Color Blue
Definition Color.h:428
void red(const unsigned char aRedValue)
static const Color Yellow
Definition Color.h:431
static const Color Cyan
Definition Color.h:429
static const Color Green
Definition Color.h:426
void blue(const unsigned char aBlueValue)
static const Color Magenta
Definition Color.h:430
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
void show() override
Starts the event loop and display of elements.
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
void randomSeeds(Image &image, const unsigned int nb, const int value)
static const L2Metric l2Metric
Definition StdDefs.h:204
HyperRectDomain< Space > Domain
Definition StdDefs.h:172
Space::Point Point
Definition StdDefs.h:168
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int max(int a, int b)
int main()
Definition testBits.cpp:56
srand(0)
Domain domain
Image image(domain)