DGtalTools  1.2.0
dicom2vol.cpp
1 
30 #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 
40 #include "CLI11.hpp"
41 
42 
43 using namespace std;
44 using namespace DGtal;
45 
46 
79 int main( int argc, char** argv )
80 {
81  typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
82 
83  // parse command line using CLI ----------------------------------------------
84  CLI::App app;
85  std::string inputFileName;
86  std::string outputFileName {"result.raw"};
87  DGtal::int64_t dicomMin {-1000};
88  DGtal::int64_t dicomMax {3000};
89 
90  app.description("Convert dicom file into a volumetric file (.vol, .longvol .pgm3d).\n Example:\n dicom2vol ${DGtal}/tests/samples/dicomSample/1629.dcm sample.vol --dicomMin 0 --dicomMax 300.");
91  app.add_option("-i,--input,1", inputFileName, "dicom image (.dcm)." )
92  ->required()
93  ->check(CLI::ExistingFile);
94  app.add_option("-o,--output,2", outputFileName, "volumetric file (.vol, .longvol .pgm3d, .raw)", true);
95  app.add_option("--dicomMin",dicomMin,"set minimum density threshold on Hounsfield scale" );
96  app.add_option("--dicomMax",dicomMax,"set maximum density threshold on Hounsfield scale" );
97 
98  app.get_formatter()->column_width(40);
99  CLI11_PARSE(app, argc, argv);
100  // END parse command line using CLI ----------------------------------------------
101 
102  typedef DGtal::functors::Rescaling<int ,unsigned char > RescalFCT;
103 
104  trace.info() << "Reading input dicom file " << inputFileName ;
105  Image3D inputImage = DicomReader< Image3D, RescalFCT >::importDicom(inputFileName,
106  RescalFCT(dicomMin,dicomMax, 0, 255) );
107  trace.info() << " [done] " << std::endl ;
108  trace.info() << " converting into vol file... " ;
109  inputImage >> outputFileName;
110  trace.info() << " [done] " << std::endl ;
111 
112  return EXIT_SUCCESS;
113 }
114 
115 
116 
117 
Definition: ATu0v1.h:57