DGtalTools  1.5.beta
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 {
102  DGtal::int32_t, double > 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);
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  const std::string ext = outputFileName.substr( outputFileName.find_last_of(".") + 1 );
139  if (std::find(ITK_IO_IMAGE_EXT.begin(),
140  ITK_IO_IMAGE_EXT.end(), ext) != ITK_IO_IMAGE_EXT.end() )
141  {
142  ITKWriter<SamplerImageAdapter>::exportITK(outputFileName, sampledImage,
143  Z3i::RealPoint(aGridSizeReSample[0],
144  aGridSizeReSample[1],
145  aGridSizeReSample[2]));
146  }
147  else
148  {
149  GenericWriter<SamplerImageAdapter>::exportFile(outputFileName, sampledImage);
150  }
151 
152 #else
153  GenericWriter<SamplerImageAdapter>::exportFile(outputFileName, sampledImage);
154 #endif
155 
156  return 0;
157 }
int main(int argc, char **argv)
const Domain & domain() const
std::ostream & info()
Trace trace(traceWriterTerm)
boost::int32_t int32_t