DGtalTools  0.9.4
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 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
39 
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z3i;
44 
45 namespace po = boost::program_options;
46 
47 
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 ----------------------------------------------
104  po::options_description general_opt ( "Allowed options are: " );
105  general_opt.add_options()
106  ( "help,h", "display this message." )
107  ( "input,i", po::value<std::string>(), "Input vol file." )
108  ( "output,o", po::value<std::string>(), "volumetric output file (.vol, .pgm, .pgm3d, .longvol) " )
109  ( "inMin,m", po::value<int>()->default_value(0), "the min value of the input image." )
110  ( "inMax,M", po::value<int>()->default_value(255), "the max value of the input image." )
111  ( "outMin", po::value<int>()->default_value(0), "the min value of the output image." )
112  ( "outMax", po::value<int>()->default_value(255), "the max value of the output image." );
113 
114  bool parseOK=true;
115  po::variables_map vm;
116 
117  try{
118  po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
119  }catch(const std::exception& ex){
120  parseOK=false;
121  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
122  }
123  //Parse options
124  if (parseOK && ! ( vm.count ( "input" ) ) ) {parseOK=false; missingParam ( "--input" );};
125  if (parseOK && ! ( vm.count ( "output" ) ) ) {parseOK=false; missingParam ( "--output" );};
126 
127 
128  po::notify ( vm );
129  if (!parseOK || vm.count ( "help" ))
130  {
131  trace.info() << "Apply a linear rescaling of the image intensity from an input intensity interval [InMin, InMax] into an output interval [OutMin, OutMax]." <<std::endl
132  << std::endl << "Basic usage: "<<std::endl
133  << "\t volIntensityScale --input <volFileName> --output <volOutputFileName> (both files can be independently in vol, pgm3D, p3d format)"<<std::endl
134  << general_opt << "\n";
135  std::cout << "Example:\n"
136  << "volIntensityScale -i ${DGtal}/examples/samples/lobster.vol --inMin 0 --inMax 100 -o lobster0-100.vol \n";
137  return 0;
138  }
139 
140 
141 
142  std::string filename = vm["input"].as<std::string>();
143  std::string outputFileName = vm["output"].as<std::string>();
144 
145  int inMin = vm["inMin"].as<int>();
146  int inMax = vm["inMax"].as<int>();
147  int outMin = vm["outMin"].as<int>();
148  int outMax = vm["outMax"].as<int>();
149 
150  trace.beginBlock("Loading file");
151 
154  MyImageC image = VolReader< MyImageC, RescalFCT >::importVol( filename,
155  RescalFCT(inMin,
156  inMax,
157  outMin, outMax));
158  trace.endBlock();
159 
160 
161  trace.beginBlock("Exporting...");
162  bool res = GenericWriter<MyImageC>::exportFile(outputFileName, image);
163  trace.endBlock();
164  if (res) return 0; else return 1;
165 }
166 
167 
168 
169 
void beginBlock(const std::string &keyword="")
STL namespace.
double endBlock()
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()