File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
distancetransform3D.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
Include dependency graph for distancetransform3D.cpp:

Go to the source code of this file.

Functions

template<typename Image>
void randomSeeds (Image &image, const unsigned int nb, const int value)
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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/01/04

This file is part of the DGtal library.

Definition in file distancetransform3D.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 99 of file distancetransform3D.cpp.

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}
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...
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
ImageContainerBySTLVector< Domain, Value > Type
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int max(int a, int b)
Domain domain
Image image(domain)

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::Color::Blue, DGtal::Color::blue(), DGtal::Color::Cyan, domain, DGtal::Color::Green, DGtal::Color::green(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Z3i::l2Metric, DGtal::Color::Magenta, max(), randomSeeds(), DGtal::Color::Red, DGtal::Color::red(), DGtal::PolyscopeViewer< Space, KSpace >::show(), and DGtal::Color::Yellow.

◆ randomSeeds()

template<typename Image>
void randomSeeds ( Image & image,
const unsigned int nb,
const int value )

Set to a given value a random set of nb points.

Parameters
imagethe image
nbthe number of random points to insert
valuethe value to add at each random point

Definition at line 80 of file distancetransform3D.cpp.

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}
srand(0)

References dim, image(), and srand().

Referenced by main().