Example of distance transformation in dimension 2.
#include <iostream>
#include <iomanip>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/TickedColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
template<typename Image>
{
typename Image::Point p, low =
image.domain().lowerBound();
typename Image::Vector ext;
for (unsigned int k = 0 ; k < nb; k++)
{
for (
unsigned int dim = 0;
dim < Image::dimension;
dim++)
image.setValue(p, value);
}
}
{
trace.beginBlock (
"Example distancetransform2D" );
for ( Image::Iterator it =
image.begin(), itend =
image.end();it != itend; ++it)
(*it)=128;
PointPredicate predicate(
image,0);
DTL2::Value maxv2=0;
for ( DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(), itend = dtL2.constRange().end();it != itend; ++it)
if ( (*it) > maxv2) maxv2 = (*it);
DTL1::Value maxv1=0;
for ( DTL1::ConstRange::ConstIterator it = dtL1.constRange().begin(), itend = dtL1.constRange().end();it != itend; ++it)
if ( (*it) > maxv1) maxv1 = (*it);
trace.warning() << dtL2 <<
" maxValue= "<<maxv2<< endl;
board.
saveSVG (
"example-DT-L2.svg" );
trace.warning() << dtL1 <<
" maxValue= "<<maxv1<< endl;
board.
saveSVG (
"example-DT-L1.svg" );
ticked.addRegularTicks(5, 0.5);
ticked.finalize();
for ( DTL2::Domain::ConstIterator it = dtL2.domain().begin(), itend = dtL2.domain().end();it != itend; ++it)
{
board << *it;
}
board.
saveSVG(
"example-DT-L2-ticked.svg");
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
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...
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
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
static const L1Metric l1Metric
HyperRectDomain< Space > Domain
static const L2Metric l2Metric
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
ImageContainerBySTLVector< Domain, Value > Type
ImageContainerBySTLVector< Domain, Value > Image