This example shows the computation of the VCM of a set of 2D digital points. The normal is estimated from the diagonalization of the VCM tensor. Feature detection is achieved with the eigenvalues of the VCM. A red color indicates a feature. Normals are displayed as arrows.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/BasicPointPredicates.h"
#include "DGtal/math/linalg/EigenDecomposition.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "ConfigExamples.h"
{
typedef LinearAlgebraTool::Matrix Matrix;
vector<unsigned int> vPos;
vPos.push_back(0);
vPos.push_back(1);
string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
trace.
info() <<
"Reading input 2d discrete points file: " << inputSDP;
trace.
info() <<
" [done] " << std::endl ;
const double R = 20;
trace.
info() <<
"Big radius R = " << R << std::endl;
const double r = 5;
trace.
info() <<
"Small radius r = " << r << std::endl;
const double T = 0.1;
trace.
info() <<
"Feature thres. T = " << T << std::endl;
const double size = 3.0;
Metric l2;
VCM vcm( R, ceil( r ), l2, true );
vcm.init( pts.begin(), pts.end() );
KernelFunction chi( 1.0, r );
Matrix vcm_r, evec;
RealVector eval;
for ( std::vector<Point>::const_iterator it = pts.begin(), itE = pts.end();
it != itE; ++it )
{
vcm_r = vcm.measure( chi, *it );
LinearAlgebraTool::getEigenDecomposition( vcm_r, evec, eval );
double feature = eval[ 0 ] / ( eval[ 0 ] + eval[ 1 ] );
new CustomColors( Color::Black, colormap( feature > T ? T : feature ) ) )
<< *it;
RealVector normal = evec.column( 1 );
Display2DFactory::draw( board, size*normal, p );
Display2DFactory::draw( board, -size*normal, p );
}
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: This class provides methods to compute the eigen decomposition of a matrix. Its objective is to ...
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: This class precomputes the Voronoi Covariance Measure of a set of points. It can compute the cov...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
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 ...
Aim: Implements method to read a set of points represented in each line of a file.
HyperRectDomain< Space > Domain