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>
40 using namespace DGtal;
85 void missingParam ( std::string param )
87 trace.error() <<
" Parameter: "<<param<<
" is required..";
88 trace.info() <<std::endl;
93 int main(
int argc,
char**argv)
98 std::string inputFileName;
99 std::string outputFileName {
"result.raw"};
100 DGtal::int64_t rescaleInputMin {0};
101 DGtal::int64_t rescaleInputMax {255};
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." )
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);
112 app.get_formatter()->column_width(40);
113 CLI11_PARSE(app, argc, argv);
117 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
118 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
119 MyImageC imageC = GenericReader< MyImageC >::importWithValueFunctor( inputFileName ,RescalFCT(rescaleInputMin,
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;