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"
using namespace std;
template<typename Image>
{
ext = image.extent();
for (unsigned int k = 0 ; k < nb; k++)
{
for (
unsigned int dim = 0;
dim < Image::dimension;
dim++)
image.setValue(p, value);
}
}
{
typedef ImageSelector<Z2i::Domain, unsigned int>::Type
Image;
for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
(*it)=128;
typedef GrayscaleColorMap<Image::Value> Gray;
Board2D board;
Display2DFactory::drawImage<Gray>(board, image, (unsigned int)0, (unsigned int)129);
board.saveSVG("inputShape.svg");
typedef functors::SimpleThresholdForegroundPredicate<Image> PointPredicate;
PointPredicate predicate(image,0);
typedef DistanceTransformation<Z2i::Space, PointPredicate, Z2i::L2Metric> DTL2;
typedef DistanceTransformation<Z2i::Space, PointPredicate, Z2i::L1Metric> DTL1;
DTL2 dtL2(image.domain(), predicate, Z2i::l2Metric);
DTL1 dtL1(image.domain(), predicate, Z2i::l1Metric);
if ( (*it) > maxv2) maxv2 = (*it);
if ( (*it) > maxv1) maxv1 = (*it);
typedef HueShadeColorMap<DTL2::Value, 2> HueTwice;
board.clear();
Display2DFactory::drawImage<HueTwice>(board, dtL2, 0.0, maxv2 + 1);
board.saveSVG ( "example-DT-L2.svg" );
board.clear();
Display2DFactory::drawImage<HueTwice>(board, dtL1, 0.0, maxv1 + 1);
board.saveSVG ( "example-DT-L1.svg" );
board.clear();
TickedColorMap<double, GradientColorMap<double> > ticked(0.0,maxv2, Color::White);
ticked.addRegularTicks(5, 0.5);
ticked.finalize();
ticked.colormap()->addColor( Color::Red );
ticked.colormap()->addColor( Color::Black );
{
board<< CustomStyle((*it).className(),new CustomColors(ticked(dtL2(*it)),ticked(dtL2(*it))));
board << *it;
}
board.saveSVG("example-DT-L2-ticked.svg");
return 0;
}
void beginBlock(const std::string &keyword="")
DigitalPlane::Point Vector
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
unsigned int dim(const Vector &z)