31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/io/readers/GenericReader.h"
35 #include "DGtal/io/writers/GenericWriter.h"
36 #include "DGtal/kernel/BasicPointFunctors.h"
42 using namespace DGtal;
74 int main(
int argc,
char** argv )
76 typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
77 typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char > Image2D;
81 std::vector<std::string> vectImage2DNames;
82 std::string outputFileName {
"result.vol"};
83 unsigned int sliceOrientation {2};
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)")
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}));
93 app.get_formatter()->column_width(40);
94 CLI11_PARSE(app, argc, argv);
99 std::vector<Image2D> vectImages2D;
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;
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()));
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));
127 trace.info() <<
"Exporting 3d image ... " << std::endl ;
128 GenericWriter<Image3D>::exportFile(outputFileName, imageResult);
129 trace.info() <<
"[done]";