DGtalTools  1.2.0
slice2vol.cpp
1 
30 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 
34 #include "DGtal/io/readers/GenericReader.h"
35 #include "DGtal/io/writers/GenericWriter.h"
36 #include "DGtal/kernel/BasicPointFunctors.h"
37 
38 #include "CLI11.hpp"
39 
40 
41 using namespace std;
42 using namespace DGtal;
43 
44 
74 int main( int argc, char** argv )
75 {
76  typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
77  typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char > Image2D;
78 
79  // parse command line using CLI ----------------------------------------------
80  CLI::App app;
81  std::vector<std::string> vectImage2DNames;
82  std::string outputFileName {"result.vol"};
83  unsigned int sliceOrientation {2};
84 
85  app.description("Converts set of 2D images into volumetric file (pgm3d, vol, longvol).\nExample:\n slice2vol -i slice1.pgm slice2.pgm slice3.pgm -o out.vol see vol2slice");
86  app.add_option("-i,--input", vectImage2DNames, "input 2D files (.pgm)")
87  -> required();
88  app.add_option("-o,--output", outputFileName, "volumetric file (.vol, .longvol .pgm3d)");
89  app.add_option("--sliceOrientation,-s", sliceOrientation, "specify the slice orientation for which the slice are defined (by default =2 (Z direction))", true)
90  -> check(CLI::IsMember({0, 1, 2}));
91 
92 
93  app.get_formatter()->column_width(40);
94  CLI11_PARSE(app, argc, argv);
95  // END parse command line using CLI ----------------------------------------------
96 
97 
98 
99  std::vector<Image2D> vectImages2D;
100  // Reading all images
101  for(unsigned int i=0; i< vectImage2DNames.size(); i++){
102  trace.info() << "Reading image " << i ;
103  Image2D image = GenericReader<Image2D>::import(vectImage2DNames.at(i));
104  vectImages2D.push_back(image);
105  trace.info() << " [done]" << std::endl;
106  }
107 
108  Image2D::Domain domImage2D = vectImages2D.at(0).domain();
109  DGtal::functors::Projector<DGtal::Z3i::Space> projIn3Dlower(0);
110  DGtal::functors::Projector<DGtal::Z3i::Space> projIn3Dupper(vectImages2D.size()-1);
111  projIn3Dlower.initAddOneDim(sliceOrientation);
112  projIn3Dupper.initAddOneDim(sliceOrientation);
113  Image3D::Domain domImage3D (projIn3Dlower(vectImages2D.at(0).domain().lowerBound()),
114  projIn3Dupper(vectImages2D.at(0).domain().upperBound()));
115 
116  Image3D imageResult (domImage3D);
117  for( unsigned int i=0; i<vectImages2D.size(); i++){
118  Image2D sliceImage = vectImages2D.at(i);
119  DGtal::functors::Projector<DGtal::Z3i::Space> projIn3D(i);
120  projIn3D.initAddOneDim(sliceOrientation);
121  for(Image2D::Domain::ConstIterator it = sliceImage.domain().begin();
122  it!= sliceImage.domain().end(); it++){
123  Z3i::Point pt =projIn3D(*it);
124  imageResult.setValue(pt, sliceImage(*it));
125  }
126  }
127  trace.info() << "Exporting 3d image ... " << std::endl ;
128  GenericWriter<Image3D>::exportFile(outputFileName, imageResult);
129  trace.info() << "[done]";
130  return EXIT_SUCCESS;
131 
132 }
133 
134 
135 
136 
Definition: ATu0v1.h:57