DGtalTools  1.2.0
volIntensityScale.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/VolReader.h>
31 #include <DGtal/io/writers/VolWriter.h>
32 #include "DGtal/io/writers/GenericWriter.h"
33 #include <DGtal/helpers/StdDefs.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 #include <DGtal/images/ConstImageAdapter.h>
36 
37 #include "CLI11.hpp"
38 
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace Z3i;
43 
44 
93 void missingParam ( std::string param )
94 {
95  trace.error() <<" Parameter: "<<param<<" is required..";
96  trace.info() <<std::endl;
97 }
98 
99 
100 int main(int argc, char**argv)
101 {
102 
103  // parse command line using CLI ----------------------------------------------
104  CLI::App app;
105  std::string inputFileName;
106  std::string outputFileName {"result.vol"};
107  int inMin {0};
108  int inMax {255};
109  int outMin {0};
110  int outMax {255};
111 
112 
113  app.description("Apply a linear rescaling of the image intensity from an input intensity interval [InMin, InMax] into an output interval [OutMin, OutMax].\n Basic usage:\n volIntensityScale --input <volFileName> --output <volOutputFileName> (both files can be independently in vol, pgm3D, p3d format)\n Example: \n volIntensityScale ${DGtal}/examples/samples/lobster.vol --inMin 0 --inMax 100 lobster0-100.vol");
114 
115  app.add_option("-i,--input,1", inputFileName, "Input vol file." )
116  ->required()
117  ->check(CLI::ExistingFile);
118 
119  app.add_option("-o,--output,2",outputFileName, "volumetric output file (.vol, .pgm, .pgm3d, .longvol) ", true);
120  app.add_option("-m,--inMin", inMin, "the min value of the input image.", true);
121  app.add_option("-M,--inMax", inMax, "the max value of the input image.", true);
122  app.add_option("--outMin", outMin, "the min value of the output image.", true);
123  app.add_option("--outMax", outMax, "the max value of the output image.", true);
124 
125  app.get_formatter()->column_width(40);
126  CLI11_PARSE(app, argc, argv);
127  // END parse command line using CLI ----------------------------------------------
128 
129 
130  trace.beginBlock("Loading file");
131 
132  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
133  typedef DGtal::functors::Rescaling<int ,unsigned char > RescalFCT;
134  MyImageC image = VolReader< MyImageC, RescalFCT >::importVol( inputFileName,
135  RescalFCT(inMin,
136  inMax,
137  outMin, outMax));
138  trace.endBlock();
139 
140  trace.beginBlock("Exporting...");
141  bool res = GenericWriter<MyImageC>::exportFile(outputFileName, image);
142  trace.endBlock();
143  if (res) return 0; else return 1;
144 }
Definition: ATu0v1.h:57