DGtalTools 2.0.0
Loading...
Searching...
No Matches
curvatureScaleSpaceBCC.cpp
1
32#include <iostream>
33
34#include "DGtal/base/Common.h"
35
36#include "DGtal/shapes/ShapeFactory.h"
37#include "DGtal/shapes/Shapes.h"
38#include "DGtal/helpers/StdDefs.h"
39#include "DGtal/topology/helpers/Surfaces.h"
40
41//Grid curve
42#include "DGtal/geometry/curves/FreemanChain.h"
43
44//Estimators
45#include "DGtal/geometry/curves/BinomialConvolver.h"
46
47
48// Generation of resulting image
49#include "DGtal/images/ImageContainerBySTLVector.h"
50#include "DGtal/io/writers/GenericWriter.h"
51#include "DGtal/io/colormaps/GradientColorMap.h"
52#include "DGtal/io/writers/PPMWriter.h"
53
54#include "CLI11.hpp"
55
56#include <vector>
57#include <string>
58#include <iomanip>
59
60
61using namespace DGtal;
62
63
64
109void
110computeCurvatureBCC(double h, const FreemanChain<Z2i::Integer> &fc, std::vector<double> &resCurvature,
111 bool isClosed){
112 std::vector<Z2i::Point> vectPoints;
113 FreemanChain<Z2i::Integer>::getContourPoints( fc, vectPoints );
114
115 typedef BinomialConvolver<std::vector<Z2i::Point>::const_iterator, double> MyBinomialConvolver;
116 typedef CurvatureFromBinomialConvolverFunctor< MyBinomialConvolver, double > CurvatureBCFct;
117 BinomialConvolverEstimator< MyBinomialConvolver, CurvatureBCFct> BCCurvatureEstimator;
118 BCCurvatureEstimator.init( h, vectPoints.begin(), vectPoints.end(), isClosed );
119 resCurvature.clear();
120 resCurvature.resize(vectPoints.size());
121 BCCurvatureEstimator.eval( vectPoints.begin(), vectPoints.end(), resCurvature.begin() );
122}
123
124
125
127
128int main( int argc, char** argv )
129{
130
131 // parse command line CLI ----------------------------------------------
132 CLI::App app;
133 std::string fileName;
134 std::string outputFileName;
135 double h_initial {1.0};
136 double h_increment {1.0};
137 double h_final {1.0};
138 double curvatureCutOff {10};
139
140 app.description("Generate the Curvature Scale Space image using a binomial convolver based estimator.\n Typical use example:\n \t curvatureScaleSpaceBCC <input filename> <output filename>\n");
141 app.add_option("-i,--input,1",fileName,"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
142 app.add_option("-o,--output,2",outputFileName,"Set the output name")->required();
143 app.add_option("--gridStepInit", h_initial, "Grid step initial");
144 app.add_option("--gridStepIncrement", h_increment, "Grid step increment ");
145 app.add_option("--gridStepFinal", h_final, "Grid step final");
146 app.add_option("--curvatureCutOff,-c", curvatureCutOff, "set the curvature limits to better display");
147
148 app.get_formatter()->column_width(40);
149 CLI11_PARSE(app, argc, argv);
150 // END parse command line using CLI ----------------------------------------------
151
152 typedef ImageContainerBySTLVector<Z2i::Domain, double > Image2D;
153
154
155 std::vector< DGtal::FreemanChain<Z2i::Integer> > vectFcs = PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (fileName);
156 bool isClosed = vectFcs.at(0).isClosed();
157
158
159 // Preparing resulting image:
160 unsigned int height = (int)((h_final-h_initial)/h_increment);
161 // We add one point if the freemnchain is open.
162 Z2i::Domain domain (Z2i::Point(0,0), Z2i::Point(vectFcs.at(0).size()+(isClosed? 0: 1), height-1));
163 Image2D cssImage(domain);
164 HueShadeColorMap<double> gradCurvature (-curvatureCutOff, curvatureCutOff);
165
166 trace.progressBar(0, height);
167 double h= h_initial;
168 for(double l= 0; l < height; l++ ){
169 // Binomial estimator
170 trace.progressBar(l, height);
171 std::vector<double> curvaturesBCC;
172 computeCurvatureBCC(h, vectFcs.at(0), curvaturesBCC, isClosed);
173 // Output
174 unsigned int j = 0;
175 for ( std::vector<double>::const_iterator it = curvaturesBCC.begin(), it_end = curvaturesBCC.end();
176 it != it_end; ++it, ++j ) {
177 double c = *it;
178 c = c<-curvatureCutOff? -curvatureCutOff: c;
179 c = c>curvatureCutOff? curvatureCutOff: c;
180 cssImage.setValue(Z2i::Point(j, l), c);
181 }
182 h=h+h_increment;
183 }
184 trace.progressBar(height, height);
185 trace.info() <<std::endl;
186 DGtal::GenericWriter<Image2D, 2, DGtal::Color, HueShadeColorMap<double> >::exportFile(outputFileName, cssImage, gradCurvature );
187 return 0;
188}
189
Definition ATu0v1.h:57