DGtal 2.1.0
Loading...
Searching...
No Matches
tutorial-examples/volDTGranulo.cpp

Example of tutorial 3: Volumetric analysis and Granulometry

See also
Tutorial: Volumetric analysis and Granulometry
result on obtained examples/samples/Al.100.vol.
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/VolWriter.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include <boost/algorithm/minmax_element.hpp>
using namespace DGtal;
int main(int, char** argv)
{
//Loarding the image
trace.info() << image << std::endl;
//Viewer
for(Image::Domain::ConstIterator it = image.domain().begin(),
itend = image.domain().end(); it != itend; ++it)
if (image(*it) != 0)
viewer << *it;
trace.info() << "viewer launched..."<<std::endl;
viewer.show();
//DT
Predicate binaryshape(image, 0);
DT distancemap(image.domain(), binaryshape, l2);
//Viewer
trace.info() << "we display the dt map"<<std::endl;
int cpt=0;
viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
itend = distancemap.domain().end(); it != itend;
++it)
if (distancemap(*it) > 0)
{
viewer2 << DGtal::WithQuantity(*it, "value", distancemap(*it));
cpt++;
}
trace.info() << "Got "<<cpt<<" points."<<std::endl;
trace.info() << "viewer2 launched..."<<std::endl;
viewer2.show();
//Granulo
Image imageGranulo ( image.domain() );
for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
it != itend; ++it)
*it = 0;
trace.info() << "Computing the granulometry"<<std::endl;
cpt=0;
for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
itend = imageGranulo.domain().end(); it != itend; ++it)
{
if (distancemap(*it) > 0)
{
//Construct the sphere with radius from distancemap(*it)
Z3i::RealPoint center = *it;
unsigned int radius = (unsigned int)distancemap(*it);
ImplicitBall<Z3i::Space> ball(center,radius);
Z3i::Point low(ball.getLowerBound() - Z3i::RealPoint::diagonal(1.0), functors::Floor<>());
Z3i::Point up (ball.getUpperBound() + Z3i::RealPoint::diagonal(1.0), functors::Ceil<>());
Z3i::Domain dom(low,up);
for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
itball != itendball; itball++)
if (imageGranulo.domain().isInside(*itball) &&
( ball(*itball) > 0) &&
(imageGranulo(*itball) < radius))
imageGranulo.setValue(*itball, radius);
cpt++;
}
}
trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
trace.info() << "Save OK"<< std::endl;
//Viewer
viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
cpt=0;
for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
itend = imageGranulo.domain().end(); it != itend;
++it)
if (imageGranulo(*it) > 0)
{
viewer3 << DGtal::WithQuantity(*it, "value", imageGranulo(*it));
cpt++;
}
trace.info() << "Got "<<cpt<<" points."<<std::endl;
trace.info() << "viewer3 launched..."<<std::endl;
viewer3.show();
return 0;
}
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
const ConstIterator & begin() const
const ConstIterator & end() const
const Domain & domain() const
Definition Image.h:192
Range range()
Definition Image.h:214
void setValue(const Point &aPoint, const Value &aValue)
Definition Image.h:247
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
RealPoint getUpperBound() const
RealPoint getLowerBound() const
Aim: Implements basic operations that will be used in Point and Vector classes.
void show() override
Starts the event loop and display of elements.
std::ostream & info()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
DGtal is the top-level namespace which contains all DGtal functions and types.
Clipping plane.
Definition Display3D.h:299
Aim: implements methods to read a "Vol" file format.
Definition VolReader.h:90
Aim: Export a 3D Image using the Vol formats.
Definition VolWriter.h:69
Attach a property to an element.
Definition Display3D.h:331
Functor that rounds up.
Functor that rounds down.
int main()
Definition testBits.cpp:56
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image