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"
51 using namespace DGtal;
106 int main(
int argc,
char** argv )
111 std::string inputFileName;
112 std::string outputFileName=
"result.pgm";
113 unsigned int border {0};
114 std::vector<int> space;
116 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");
117 app.add_option(
"-i,--input,1", inputFileName,
"Input freeman chain file name." )
119 ->check(CLI::ExistingFile);
120 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.");
121 app.add_option(
"-o,--output,2", outputFileName,
"the output fileName",
true);
122 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." )
126 app.get_formatter()->column_width(40);
127 CLI11_PARSE(app, argc, argv);
131 typedef KhalimskySpaceND<2, int>::Cell Cell;
132 typedef KhalimskySpaceND<2, int>::SCell SCell;
133 typedef FreemanChain<Z2i::Integer> FreemanChain;
134 typedef DGtal::KhalimskySpaceND< 2, int > KSpace;
135 typedef DGtal::ImageContainerBySTLVector<Z2i::Domain, unsigned char> Image2D ;
138 std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >::getFreemanChainsFromFile<Z2i::Integer> (inputFileName);
139 int minx=std::numeric_limits<int>::max();
140 int miny=std::numeric_limits<int>::max();
141 int maxx=std::numeric_limits<int>::min();
142 int maxy=std::numeric_limits<int>::min();
146 for(std::vector< FreemanChain >::const_iterator it = vectFcs.begin(); it!= vectFcs.end(); it++){
147 FreemanChain fc = *it;
148 int t_minx=std::numeric_limits<int>::max();
149 int t_miny=std::numeric_limits<int>::max();
150 int t_maxx=std::numeric_limits<int>::min();
151 int t_maxy=std::numeric_limits<int>::min();
152 fc.computeBoundingBox(t_minx, t_miny, t_maxx, t_maxy);
153 minx = t_minx > minx? minx: t_minx;
154 miny = t_miny > miny? miny: t_miny;
155 maxx = t_maxx < maxx? maxx: t_maxx;
156 maxy = t_maxy < maxy? maxy: t_maxy;
158 minx-=border; miny-=border; maxx+=border; maxy+=border;
166 aKSpace.init(Z2i::Point(minx, miny), Z2i::Point(maxx, maxy),
true);
167 std::set<SCell> boundarySCell;
168 std::set<Cell> interiorCell;
169 for(std::vector< FreemanChain >::const_iterator it = vectFcs.begin(); it!= vectFcs.end(); it++){
170 FreemanChain fc = *it;
171 FreemanChain::getInterPixelLinels(aKSpace, fc, boundarySCell,
true);
174 Image2D imageResult (Z2i::Domain(Z2i::Point(minx, miny), Z2i::Point(maxx, maxy)));
175 Surfaces<KSpace>::uFillInterior(aKSpace, functors::SurfelSetPredicate<std::set<SCell>,SCell>(boundarySCell), imageResult, 255,
false,
false );
176 imageResult >> outputFileName;