DGtalTools  1.2.0
volReSample.cpp
1 
30 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 
34 #include "DGtal/io/readers/GenericReader.h"
35 #include "DGtal/io/writers/GenericWriter.h"
36 #include "DGtal/images/ConstImageAdapter.h"
37 #include "DGtal/kernel/BasicPointFunctors.h"
38 
39 #include "CLI11.hpp"
40 
41 
42 using namespace std;
43 using namespace DGtal;
44 
45 
98 int main( int argc, char** argv )
99 {
100  typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;
101  typedef DGtal::functors::BasicDomainSubSampler< HyperRectDomain<SpaceND<3, int> >,
102  DGtal::int32_t, double > ReSampler;
103  typedef DGtal::ConstImageAdapter<Image3D, Image3D::Domain, ReSampler,
104  Image3D::Value, DGtal::functors::Identity > SamplerImageAdapter;
105 
106 
107 
108  // parse command line using CLI ----------------------------------------------
109  CLI::App app;
110  std::string inputFileName;
111  std::string outputFileName {"result.vol"};
112  std::vector<double> aGridSizeReSample;
113 
114  app.description("Re sample a 3D volumetric image (.vol, .longvol, .pgm3d) with a given grid size. \n Example:\n to re sample an image with scale x,y,z = 0.98, 0.98, 5.0, you can do:\n volResSample -i image3d.vol -g 1 1 2 -o imageReSampled.vol \n "
115  "Note that if DGtal is compiled with the option WITH_ITK set to ON, you can export the image in format ITK format and integrating image spacing.");
116  app.add_option("-i,--input,1", inputFileName, "input volumetric file (.vol, .longvol, .pgm3d)." )
117  ->required()
118  ->check(CLI::ExistingFile);
119  app.add_option("-o,--output,2", outputFileName, "the new volumetric file (.vol, .longvol, .pgm3d).", true );
120  app.add_option("-g,--gridSize", aGridSizeReSample, "size_x size_y size_z : the grid size of the re sampling ")
121  ->expected(3);
122  app.get_formatter()->column_width(40);
123  CLI11_PARSE(app, argc, argv);
124  // END parse command line using CLI ----------------------------------------------
125 
126 
127  trace.info()<< "Importing volume file : " << inputFileName<< " ... " ;
128  Image3D input3dImage = GenericReader<Image3D>::import(inputFileName);
129  trace.info()<< "[done]" << endl;
130 
131  PointVector<3,int> shiftVector3D(0 ,0, 0);
132  DGtal::functors::BasicDomainSubSampler< HyperRectDomain<SpaceND<3, int> >,
133  DGtal::int32_t, double > reSampler(input3dImage.domain(),
134  aGridSizeReSample, shiftVector3D);
135  const functors::Identity aFunctor{};
136  SamplerImageAdapter sampledImage ( input3dImage, reSampler.getSubSampledDomain(), reSampler, aFunctor );
137 #ifdef WITH_ITK
138  ITKWriter<SamplerImageAdapter>::exportITK(outputFileName, sampledImage,
139  Z3i::RealPoint(aGridSizeReSample[0],
140  aGridSizeReSample[1],
141  aGridSizeReSample[2]));
142 #else
143  GenericWriter<SamplerImageAdapter>::exportFile(outputFileName, sampledImage);
144 
145 #endif
146 
147  return 0;
148 }
Definition: ATu0v1.h:57