DGtalTools  0.9.4
vol2raw.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/GenericReader.h>
31 #include <DGtal/io/writers/RawWriter.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace Z3i;
43 
44 namespace po = boost::program_options;
45 
85 void missingParam ( std::string param )
86 {
87  trace.error() <<" Parameter: "<<param<<" is required..";
88  trace.info() <<std::endl;
89  exit ( 1 );
90 }
91 
92 
93 int main(int argc, char**argv)
94 {
95 
96  // parse command line ----------------------------------------------
97  po::options_description general_opt ( "Allowed options are: " );
98  general_opt.add_options()
99  ( "help,h", "display this message." )
100  ("input,i", po::value<std::string>(), "vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
101  ( "output,o", po::value<string>(),"Output filename." )
102  ("rescaleInputMin", po::value<DGtal::int64_t>()->default_value(0), "min value used to rescale the input intensity (to avoid basic cast into 8 bits image).")
103  ("rescaleInputMax", po::value<DGtal::int64_t>()->default_value(255), "max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
104  bool parseOK=true;
105  po::variables_map vm;
106  try{
107  po::store(po::parse_command_line(argc, argv, general_opt), vm);
108  }catch(const std::exception& ex){
109  parseOK=false;
110  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
111  }
112  po::notify ( vm );
113  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
114  {
115  trace.info() << "Convert a vol to a 8-bit raw file."<<std::endl
116  << std::endl << "Basic usage: "<<std::endl
117  << "\tvol2raw --input <volFileName> --o <RawOutputFileName> "<<std::endl
118  << general_opt << "\n";
119  return 0;
120  }
121 
122  //Parse options
123  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
124  std::string filename = vm["input"].as<std::string>();
125  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
126  std::string outputFileName = vm["output"].as<std::string>();
127  DGtal::int64_t rescaleInputMin = vm["rescaleInputMin"].as<DGtal::int64_t>();
128  DGtal::int64_t rescaleInputMax = vm["rescaleInputMax"].as<DGtal::int64_t>();
129 
132  MyImageC imageC = GenericReader< MyImageC >::importWithValueFunctor( filename ,RescalFCT(rescaleInputMin,
133  rescaleInputMax,
134  0, 255) );
135 
136 
137 
138  bool res = RawWriter< MyImageC >::exportRaw8(outputFileName, imageC);
139  trace.info() << "Raw export done, image dimensions: " << imageC.domain().upperBound()[0]-imageC.domain().lowerBound()[0]+1
140  << " " << imageC.domain().upperBound()[1]-imageC.domain().lowerBound()[1]+1
141  << " " << imageC.domain().upperBound()[2]-imageC.domain().lowerBound()[2]+1 << std::endl;
142 
143  if (res) return 0; else return 1;
144 }
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()
boost::int64_t int64_t