DGtal  1.3.beta
geometry/volumes/distance/distancetransform3D.cpp

Example of distance transformation in dimension 3 with DGtal Viewer3D. This program outputs this image:

See also
nD Volumetric Analysis using Separable Processes
#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/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
using namespace std;
using namespace DGtal;
template<typename Image>
void randomSeeds(Image &image, const unsigned int nb, const int value)
{
typename Image::Point p, low = image.domain().lowerBound();
typename Image::Vector ext;
srand ( time(NULL) );
ext = image.extent();
for (unsigned int k = 0 ; k < nb; k++)
{
for (unsigned int dim = 0; dim < Image::dimension; dim++)
p[dim] = rand() % (ext[dim]) + low[dim];
image.setValue(p, value);
}
}
using namespace DGtal;
int main( int argc, char** argv )
{
std::string inputFilename = examplesPath + "samples/Al.100.vol";
//------------
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.setWindowTitle("simpleViewer");
viewer.show();
//Default image selector = STLVector
Image image = VolReader<Image>::importVol( inputFilename );
Z3i::Domain domain = image.domain();
Image imageSeeds ( domain);
for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
(*it)=1;
Z3i::Point p0(10,10,10);
//imageSeeds.setValue(p0, 0 );
randomSeeds(imageSeeds, 70, 0);
//Distance transformation computation
Predicate aPredicate(imageSeeds,0);
DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
unsigned int min = 0;
unsigned int max = 0;
for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
itend=dtL2.constRange().end();
it!=itend;
++it)
{
if( (*it) < min )
min=(*it);
if( (*it) > max )
max=(*it);
}
GradientColorMap<long> gradient( 0,30);
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
it!=itend;
++it){
double valDist= dtL2( (*it) );
Color c= gradient(valDist);
if(dtL2(*it)<=30 && image(*it)>0){
viewer << CustomColors3D(Color((float)(c.red()),
(float)(c.green()),
(float)(c.blue(),205)),
Color((float)(c.red()),
(float)(c.green()),
(float)(c.blue()),205));
viewer << *it ;
}
}
viewer<< Viewer3D<>::updateDisplay;
return application.exec();
}
// //
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
image
Image image(domain)
DGtal::HyperRectDomain< Space >
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
srand
srand(0)
dim
unsigned int dim(const Vector &z)
Definition: viewDualSurface.cpp:174
DGtal::Viewer3D
Definition: Viewer3D.h:135
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:264
randomSeeds
void randomSeeds(Image &input, const unsigned int nb, const int value)
Definition: testDistanceTransformation.cpp:60
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector< dim, Integer >
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition: DistanceTransformation.h:98
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition: SimpleThresholdForegroundPredicate.h:65