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/ITKReader.h"
39 #include <boost/program_options/options_description.hpp>
40 #include <boost/program_options/parsers.hpp>
41 #include <boost/program_options/variables_map.hpp>
44 using namespace DGtal;
72 namespace po = boost::program_options;
75 int main(
int argc,
char** argv )
81 po::options_description general_opt(
"Allowed options are ");
82 general_opt.add_options()
83 (
"help,h",
"display this message")
84 (
"input,i", po::value<std::string>(),
"Any file format in the ITK library (mhd, mha, ...) " )
85 (
"output,o", po::value<std::string>(),
"volumetric file (.vol, .pgm3d) " )
86 (
"inputMin", po::value<int>()->default_value(-1000),
"set minimum density threshold on Hounsfield scale")
87 (
"inputMax", po::value<int>()->default_value(3000),
"set maximum density threshold on Hounsfield scale");
94 po::store(po::parse_command_line(argc, argv, general_opt), vm);
95 }
catch(
const std::exception& ex){
97 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
100 if( !parseOK || vm.count(
"help")||argc<=1)
102 std::cout <<
"Usage: " << argv[0] <<
" [input] [output]\n"
103 <<
"Converts itk file into a volumetric file (.vol, .pgm3d). "
104 << general_opt <<
"\n";
105 std::cout <<
"Example:\n"
106 <<
"itk2vol -i image.mhd --inputMin -500 --inputMax -100 -o sample.vol \n";
110 if(! vm.count(
"input") ||! vm.count(
"output"))
112 trace.
error() <<
" Input and output filename are needed to be defined" << endl;
117 string inputFilename = vm[
"input"].as<std::string>();
118 string outputFilename = vm[
"output"].as<std::string>();
119 int inputMin = vm[
"inputMin"].as<
int>();
120 int inputMax = vm[
"inputMax"].as<
int>();
123 trace.
info() <<
"Reading input input file " << inputFilename ;
125 trace.
info() <<
" [done] " << std::endl ;
126 trace.
info() <<
" converting into vol file... " ;
127 RescalFCT rescaleCustom(inputMin, inputMax, 0, 255);
132 trace.
info() <<
" [done] " << std::endl ;
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
Trace trace(traceWriterTerm)