DGtalTools 2.0.0
Loading...
Searching...
No Matches
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
40using namespace std;
41using namespace DGtal;
42using namespace Z3i;
43
44
96int main(int argc, char**argv)
97{
98
99 // parse command line ----------------------------------------------
100 // parse command line using CLI ----------------------------------------------
101 CLI::App app;
102 std::string inputFileName;
103 std::string outputFileName {"result.vol"};
104 std::vector<unsigned int> inputVals;
105 std::vector<unsigned int> outputVals;
106
107 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.");
108
109 app.add_option("-i,--input,1", inputFileName, "Input vol file." )
110 ->required()
111 ->check(CLI::ExistingFile);
112
113 app.add_option("--output,-o,2",outputFileName, "Output filename.");
114 app.add_option("--inputVals,-s", inputVals, "specify the values which will be transformed with the output values (given with --outputVals).") ->required();
115 app.add_option("--outputVals,-r", outputVals, "specify the values which will be transformed with the output values (given with --outputVals).") ->required();
116
117
118 app.get_formatter()->column_width(40);
119 CLI11_PARSE(app, argc, argv);
120 // END parse command line using CLI ----------------------------------------------
121
122
123 if(inputVals.size()!=outputVals.size()){
124 trace.error()<< "Transformation not possible the two sets of input/output values should have the same size." << std::endl;
125 exit(1);
126 }
127
128 trace.beginBlock("Loading file");
129 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
130 MyImageC image = GenericReader< MyImageC >::import( inputFileName );
131 trace.endBlock();
132 unsigned int val;
133 for(MyImageC::Domain::ConstIterator it = image.domain().begin(),
134 itend = image.domain().end(); it != itend; ++it)
135 {
136 val = image(*it);
137 for(unsigned int i = 0; i< inputVals.size(); i++){
138 if(inputVals.at(i)==val){
139 image.setValue( *it , outputVals.at(i));
140 }
141 }
142 }
143
144 trace.beginBlock("Exporting...");
145 bool res = GenericWriter<MyImageC>::exportFile(outputFileName, image);
146 trace.endBlock();
147
148 if (res) return 0; else return 1;
149}
Definition ATu0v1.h:57