DGtalTools 2.0.0
Loading...
Searching...
No Matches
vol2raw.cpp
1
29#include <iostream>
30#include <DGtal/base/Common.h>
31#include <DGtal/io/readers/GenericReader.h>
32#include <DGtal/io/writers/RawWriter.h>
33#include <DGtal/helpers/StdDefs.h>
34#include <DGtal/images/Image.h>
35#include <DGtal/images/ImageContainerBySTLVector.h>
36
37#include "CLI11.hpp"
38
39
40using namespace std;
41using namespace DGtal;
42using namespace Z3i;
43
44
86void missingParam ( std::string param )
87{
88 trace.error() <<" Parameter: "<<param<<" is required..";
89 trace.info() <<std::endl;
90 exit ( 1 );
91}
92
93
94int main(int argc, char**argv)
95{
96
97 // parse command line using CLI ----------------------------------------------
98 CLI::App app;
99 std::string inputFileName;
100 std::string outputFileName {"result.raw"};
101 DGtal::int64_t rescaleInputMin {0};
102 DGtal::int64_t rescaleInputMax {255};
103
104 app.description("Convert a vol to a 8-bit raw file.\n Example: vol2raw ${DGtal}/examples/samples/lobster.vol res.raw \n");
105 app.add_option("-i,--input,1", inputFileName, "vol file (.vol, .longvol .p3d, .pgm3d and if DGTAL_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 ->required()
107 ->check(CLI::ExistingFile);
108 app.add_option("--output,-o,2",outputFileName ,"output file (.raw).");
109 app.add_option("--rescaleInputMin", rescaleInputMin, "min value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
110 app.add_option("--rescaleInputMax", rescaleInputMax, "max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
111
112
113 app.get_formatter()->column_width(40);
114 CLI11_PARSE(app, argc, argv);
115 // END parse command line using CLI ----------------------------------------------
116
117
118 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
119 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
120 MyImageC imageC = GenericReader< MyImageC >::importWithValueFunctor( inputFileName ,RescalFCT(rescaleInputMin,
121 rescaleInputMax,
122 0, 255) );
123
124 bool res = RawWriter< MyImageC >::exportRaw8(outputFileName, imageC);
125 trace.info() << "Raw export done, image dimensions: " << imageC.domain().upperBound()[0]-imageC.domain().lowerBound()[0]+1
126 << " " << imageC.domain().upperBound()[1]-imageC.domain().lowerBound()[1]+1
127 << " " << imageC.domain().upperBound()[2]-imageC.domain().lowerBound()[2]+1 << std::endl;
128
129 if (res)
130 return EXIT_SUCCESS;
131 else
132 return EXIT_FAILURE;
133}
Definition ATu0v1.h:57