DGtalTools  0.9.4
dicom2vol.cpp
1 
29 #include <iostream>
31 #include <fstream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/base/BasicFunctors.h"
35 #include "DGtal/images/ImageContainerBySTLVector.h"
36 #include "DGtal/io/writers/GenericWriter.h"
37 #include "DGtal/io/readers/DicomReader.h"
38 
39 #include <boost/program_options/options_description.hpp>
40 #include <boost/program_options/parsers.hpp>
41 #include <boost/program_options/variables_map.hpp>
42 
43 using namespace std;
44 using namespace DGtal;
45 
46 
73 namespace po = boost::program_options;
75 
76 int main( int argc, char** argv )
77 {
79 
80 
81  // parse command line ----------------------------------------------
82  po::options_description general_opt("Allowed options are: ");
83  general_opt.add_options()
84  ("help,h", "display this message")
85  ("input,i", po::value<std::string>(), "dicom image (.dcm) " )
86  ("output,o", po::value<std::string>(), "volumetric file (.vol, .longvol .pgm3d) " )
87  ("dicomMin", po::value<int>()->default_value(-1000), "set minimum density threshold on Hounsfield scale")
88  ("dicomMax", po::value<int>()->default_value(3000), "set maximum density threshold on Hounsfield scale");
89 
90 
91 
92  bool parseOK=true;
93  po::variables_map vm;
94  try{
95  po::store(po::parse_command_line(argc, argv, general_opt), vm);
96  }catch(const std::exception& ex){
97  parseOK=false;
98  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
99  }
100  po::notify(vm);
101  if( !parseOK || vm.count("help")||argc<=1)
102  {
103  std::cout << "Usage: " << argv[0] << " [input] [output]\n"
104  << "Convert dicom file into a volumetric file (.vol, .longvol .pgm3d) ."
105  << general_opt << "\n";
106  std::cout << "Example:\n"
107  << "dicom2vol -i ${DGtal}/tests/samples/dicomSample/1629.dcm --dicomMin -500 --dicomMax -100 -o sample.vol \n";
108  return 0;
109  }
110 
111  if(! vm.count("input") ||! vm.count("output"))
112  {
113  trace.error() << " Input and output filename are needed to be defined" << endl;
114  return 0;
115  }
116 
117 
118  string inputFilename = vm["input"].as<std::string>();
119  string outputFilename = vm["output"].as<std::string>();
120  int dicomMin = vm["dicomMin"].as<int>();
121  int dicomMax = vm["dicomMax"].as<int>();
123 
124  trace.info() << "Reading input dicom file " << inputFilename ;
125  Image3D inputImage = DicomReader< Image3D, RescalFCT >::importDicom(inputFilename,
126  RescalFCT(dicomMin,dicomMax, 0, 255) );
127  trace.info() << " [done] " << std::endl ;
128  trace.info() << " converting into vol file... " ;
129  inputImage >> outputFilename;
130  trace.info() << " [done] " << std::endl ;
131 
132 
133  return 0;
134 
135 }
136 
137 
138 
139 
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()