DGtalTools  1.3.beta
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 "CLI11.hpp"
37 
38 
39 using namespace std;
40 using namespace DGtal;
41 using namespace Z3i;
42 
43 
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 using CLI ----------------------------------------------
97  CLI::App app;
98  std::string inputFileName;
99  std::string outputFileName {"result.raw"};
100  DGtal::int64_t rescaleInputMin {0};
101  DGtal::int64_t rescaleInputMax {255};
102 
103  app.description("Convert a vol to a 8-bit raw file.\n Example: vol2raw ${DGtal}/examples/samples/lobster.vol res.raw \n");
104  app.add_option("-i,--input,1", inputFileName, "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." )
105  ->required()
106  ->check(CLI::ExistingFile);
107  app.add_option("--output,-o,2",outputFileName ,"output file (.raw).");
108  app.add_option("--rescaleInputMin", rescaleInputMin, "min value used to rescale the input intensity (to avoid basic cast into 8 bits image).", true);
109  app.add_option("--rescaleInputMax", rescaleInputMax, "max value used to rescale the input intensity (to avoid basic cast into 8 bits image).", true);
110 
111 
112  app.get_formatter()->column_width(40);
113  CLI11_PARSE(app, argc, argv);
114  // END parse command line using CLI ----------------------------------------------
115 
116 
119  MyImageC imageC = GenericReader< MyImageC >::importWithValueFunctor( inputFileName ,RescalFCT(rescaleInputMin,
120  rescaleInputMax,
121  0, 255) );
122 
123  bool res = RawWriter< MyImageC >::exportRaw8(outputFileName, imageC);
124  trace.info() << "Raw export done, image dimensions: " << imageC.domain().upperBound()[0]-imageC.domain().lowerBound()[0]+1
125  << " " << imageC.domain().upperBound()[1]-imageC.domain().lowerBound()[1]+1
126  << " " << imageC.domain().upperBound()[2]-imageC.domain().lowerBound()[2]+1 << std::endl;
127 
128  if (res)
129  return EXIT_SUCCESS;
130  else
131  return EXIT_FAILURE;
132 }
STL namespace.
int main(int argc, char **argv)
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()
boost::int64_t int64_t