32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/io/readers/PointListReader.h"
37#include "DGtal/io/writers/GenericWriter.h"
40#include "DGtal/geometry/curves/FreemanChain.h"
41#include "DGtal/topology/helpers/Surfaces.h"
42#include "DGtal/topology/SurfelSetPredicate.h"
107int main(
int argc,
char** argv )
112 std::string inputFileName;
113 std::string outputFileName=
"result.pgm";
114 unsigned int border {0};
115 std::vector<int> space;
117 app.description(
"Transform one or several freeman chains into an grayscale image file by filling its interior areas.\nThe transformation can fill shapes with hole by using the freemanchain orientation. The interior is considered on the left according to a freeman chain move, i.e. a clockwise oriented contour represents a hole in the shape. Basic example:\n \t freeman2img -i inputChain.fc -o contourDisplay.pgm -b 5");
118 app.add_option(
"-i,--input,1", inputFileName,
"Input freeman chain file name." )
120 ->check(CLI::ExistingFile);
121 app.add_option(
"-b,--border",border,
"add a border in the resulting image (used only in the automatic mode i.e when --space is not used.");
122 app.add_option(
"-o,--output,2", outputFileName,
"the output fileName");
123 app.add_option(
"-s,--space", space,
"Define the space from its bounding box (lower and upper coordinates) else the space is automatically defined from the freemanchain bounding boxes." )
127 app.get_formatter()->column_width(40);
128 CLI11_PARSE(app, argc, argv);
132 typedef KhalimskySpaceND<2, int>::Cell Cell;
133 typedef KhalimskySpaceND<2, int>::SCell SCell;
134 typedef FreemanChain<Z2i::Integer> FreemanChain;
135 typedef DGtal::KhalimskySpaceND< 2, int > KSpace;
136 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned char> Image2D ;
139 std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >::getFreemanChainsFromFile<Z2i::Integer> (inputFileName);
140 int minx=std::numeric_limits<int>::max();
141 int miny=std::numeric_limits<int>::max();
142 int maxx=std::numeric_limits<int>::min();
143 int maxy=std::numeric_limits<int>::min();
147 for(std::vector< FreemanChain >::const_iterator it = vectFcs.begin(); it!= vectFcs.end(); it++){
148 FreemanChain fc = *it;
149 int t_minx=std::numeric_limits<int>::max();
150 int t_miny=std::numeric_limits<int>::max();
151 int t_maxx=std::numeric_limits<int>::min();
152 int t_maxy=std::numeric_limits<int>::min();
153 fc.computeBoundingBox(t_minx, t_miny, t_maxx, t_maxy);
154 minx = t_minx > minx? minx: t_minx;
155 miny = t_miny > miny? miny: t_miny;
156 maxx = t_maxx < maxx? maxx: t_maxx;
157 maxy = t_maxy < maxy? maxy: t_maxy;
159 minx-=border; miny-=border; maxx+=border; maxy+=border;
167 aKSpace.init(Z2i::Point(minx, miny), Z2i::Point(maxx, maxy),
true);
168 std::set<SCell> boundarySCell;
169 std::set<Cell> interiorCell;
170 for(std::vector< FreemanChain >::const_iterator it = vectFcs.begin(); it!= vectFcs.end(); it++){
171 FreemanChain fc = *it;
172 FreemanChain::getInterPixelLinels(aKSpace, fc, boundarySCell,
true);
175 Image2D imageResult (Z2i::Domain(Z2i::Point(minx, miny), Z2i::Point(maxx, maxy)));
176 Surfaces<KSpace>::uFillInterior(aKSpace, functors::SurfelSetPredicate<std::set<SCell>,SCell>(boundarySCell), imageResult, 255,
false,
false );
177 imageResult >> outputFileName;