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" 38 #include <boost/program_options/options_description.hpp> 39 #include <boost/program_options/parsers.hpp> 40 #include <boost/program_options/variables_map.hpp> 45 using namespace DGtal;
74 namespace po = boost::program_options;
77 int main(
int argc,
char** argv )
79 typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
80 typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char > Image2D;
84 po::options_description general_opt(
"Allowed options are: ");
85 general_opt.add_options()
86 (
"help,h",
"display this message")
87 (
"sliceOrientation,s", po::value<unsigned int>()->default_value(2),
"specify the slice orientation for which the slice are considered (by default =2 (Z direction))" )
88 (
"input,i", po::value<std::vector <std::string> >()->multitoken(),
"input 2D files (.pgm) " )
89 (
"output,o", po::value<std::string>(),
"volumetric file (.vol, .longvol .pgm3d) " );
95 po::store(po::parse_command_line(argc, argv, general_opt), vm);
96 }
catch(
const std::exception& ex){
98 trace.info()<<
"Error checking program options: "<< ex.what()<< endl;
103 if( ! vm.count(
"input") || ! vm.count(
"output") || !parseOK || vm.count(
"help"))
105 std::cout <<
"Usage: " << argv[0] <<
" [input-files] [output]\n" 106 <<
"Converts set of 2D images into volumetric file (pgm3d, vol, longvol). " 107 << general_opt <<
"\n";
108 std::cout <<
"Example:\n" 109 <<
"slice2vol -i slice1.pgm slice2.pgm slice3.pgm -o out.vol \n" 110 <<
"see vol2slice"<<endl;
115 if(! (vm.count(
"input") && vm.count(
"output")) )
117 trace.error() <<
" Input and output filename are needed to be defined" << endl;
123 std::string outputFileName = vm[
"output"].as<std::string>();
124 std::vector<string> vectImage2DNames = vm[
"input"].as<std::vector<std::string> >();
125 unsigned int sliceOrientation = vm[
"sliceOrientation"].as<
unsigned int>();
126 std::vector<Image2D> vectImages2D;
128 for(
unsigned int i=0; i< vectImage2DNames.size(); i++){
129 trace.info() <<
"Reading image " << i ;
130 Image2D image = GenericReader<Image2D>::import(vectImage2DNames.at(i));
131 vectImages2D.push_back(image);
132 trace.info() <<
" [done]" << std::endl;
135 Image2D::Domain domImage2D = vectImages2D.at(0).domain();
136 DGtal::functors::Projector<DGtal::Z3i::Space> projIn3Dlower(0);
137 DGtal::functors::Projector<DGtal::Z3i::Space> projIn3Dupper(vectImages2D.size()-1);
138 projIn3Dlower.initAddOneDim(sliceOrientation);
139 projIn3Dupper.initAddOneDim(sliceOrientation);
140 Image3D::Domain domImage3D (projIn3Dlower(vectImages2D.at(0).domain().lowerBound()),
141 projIn3Dupper(vectImages2D.at(0).domain().upperBound()));
143 Image3D imageResult (domImage3D);
144 for(
unsigned int i=0; i<vectImages2D.size(); i++){
145 Image2D sliceImage = vectImages2D.at(i);
146 DGtal::functors::Projector<DGtal::Z3i::Space> projIn3D(i);
147 projIn3D.initAddOneDim(sliceOrientation);
148 for(Image2D::Domain::ConstIterator it = sliceImage.domain().begin();
149 it!= sliceImage.domain().end(); it++){
150 Z3i::Point pt =projIn3D(*it);
151 imageResult.setValue(pt, sliceImage(*it));
154 trace.info() <<
"Exporting 3d image ... " << std::endl ;
155 GenericWriter<Image3D>::exportFile(outputFileName, imageResult);
156 trace.info() <<
"[done]";