DGtalTools  1.2.0
volTrValues.cpp
1 
30 #include <iostream>
31 #include <DGtal/base/Common.h>
32 #include <DGtal/io/readers/GenericReader.h>
33 #include <DGtal/io/writers/GenericWriter.h>
34 #include <DGtal/helpers/StdDefs.h>
35 #include <DGtal/images/ImageContainerBySTLVector.h>
36 #include <DGtal/images/ConstImageAdapter.h>
37 
38 #include "CLI11.hpp"
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace Z3i;
43 
44 
95 int main(int argc, char**argv)
96 {
97 
98  // parse command line ----------------------------------------------
99  // parse command line using CLI ----------------------------------------------
100  CLI::App app;
101  std::string inputFileName;
102  std::string outputFileName {"result.vol"};
103  std::vector<unsigned int> inputVals;
104  std::vector<unsigned int> outputVals;
105 
106  app.description("Apply basic vol image transform from the input values to output values.\n Basic usage:\n \t volTrValues --input <volFileName> --o <volOutputFileName> -s 1 99 -r 100 200 \n\t => all voxel of values 1 (resp. 99) will be 100 (resp. 200) in the resulting image.");
107 
108  app.add_option("-i,--input,1", inputFileName, "Input vol file." )
109  ->required()
110  ->check(CLI::ExistingFile);
111 
112  app.add_option("--output,-o,2",outputFileName, "Output filename.", true);
113  app.add_option("--inputVals,-s", inputVals, "specify the values which will be transformed with the output values (given with --outputVals).") ->required();
114  app.add_option("--outputVals,-r", outputVals, "specify the values which will be transformed with the output values (given with --outputVals).") ->required();
115 
116 
117  app.get_formatter()->column_width(40);
118  CLI11_PARSE(app, argc, argv);
119  // END parse command line using CLI ----------------------------------------------
120 
121 
122  if(inputVals.size()!=outputVals.size()){
123  trace.error()<< "Transformation not possible the two sets of input/output values should have the same size." << std::endl;
124  exit(1);
125  }
126 
127  trace.beginBlock("Loading file");
128  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
129  MyImageC image = GenericReader< MyImageC >::import( inputFileName );
130  trace.endBlock();
131  unsigned int val;
132  for(MyImageC::Domain::ConstIterator it = image.domain().begin(),
133  itend = image.domain().end(); it != itend; ++it)
134  {
135  val = image(*it);
136  for(unsigned int i = 0; i< inputVals.size(); i++){
137  if(inputVals.at(i)==val){
138  image.setValue( *it , outputVals.at(i));
139  }
140  }
141  }
142 
143  trace.beginBlock("Exporting...");
144  bool res = GenericWriter<MyImageC>::exportFile(outputFileName, image);
145  trace.endBlock();
146 
147  if (res) return 0; else return 1;
148 }
Definition: ATu0v1.h:57