31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
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"
43 using namespace DGtal;
98 int main(
int argc,
char** argv )
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;
110 std::string inputFileName;
111 std::string outputFileName {
"result.vol"};
112 std::vector<double> aGridSizeReSample;
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)." )
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 ")
122 app.get_formatter()->column_width(40);
123 CLI11_PARSE(app, argc, argv);
127 trace.info()<<
"Importing volume file : " << inputFileName<<
" ... " ;
128 Image3D input3dImage = GenericReader<Image3D>::import(inputFileName);
129 trace.info()<<
"[done]" << endl;
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 );
138 ITKWriter<SamplerImageAdapter>::exportITK(outputFileName, sampledImage,
139 Z3i::RealPoint(aGridSizeReSample[0],
140 aGridSizeReSample[1],
141 aGridSizeReSample[2]));
143 GenericWriter<SamplerImageAdapter>::exportFile(outputFileName, sampledImage);