DGtalTools 2.0.0
Loading...
Searching...
No Matches
freeman2img.cpp
1
30#include <iostream>
31
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34
35//image
36#include "DGtal/io/readers/PointListReader.h"
37#include "DGtal/io/writers/GenericWriter.h"
38
39//contour
40#include "DGtal/geometry/curves/FreemanChain.h"
41#include "DGtal/topology/helpers/Surfaces.h"
42#include "DGtal/topology/SurfelSetPredicate.h"
43
44//STL
45#include <vector>
46#include <string>
47
48#include "CLI11.hpp"
49
50
51using namespace DGtal;
52
53
107int main( int argc, char** argv )
108{
109
110 // parse command line using CLI ----------------------------------------------
111 CLI::App app;
112 std::string inputFileName;
113 std::string outputFileName="result.pgm";
114 unsigned int border {0};
115 std::vector<int> space;
116
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." )
119 ->required()
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." )
124 ->expected(4);
125
126
127 app.get_formatter()->column_width(40);
128 CLI11_PARSE(app, argc, argv);
129 // END parse command line using CLI ----------------------------------------------
130
131
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 ;
137
138
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();
144
145
146 if(space.size()!=4){
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;
158 }
159 minx-=border; miny-=border; maxx+=border; maxy+=border;
160 }else{
161 minx = space[0];
162 miny = space[1];
163 maxx = space[2];
164 maxy = space[3];
165 }
166 KSpace aKSpace;
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);
173 }
174
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;
178
179}
180
Definition ATu0v1.h:57