DGtal  1.5.beta
2DSliceImageFromVol.cpp
1 
31 #include <iostream>
32 #include <DGtal/base/Common.h>
33 #include "DGtal/io/readers/GenericReader.h"
34 #include "DGtal/io/writers/GenericWriter.h"
35 
36 #include <DGtal/helpers/StdDefs.h>
37 #include <DGtal/images/ImageContainerBySTLVector.h>
38 #include <DGtal/images/ConstImageAdapter.h>
39 
40 
41 #include "DGtal/kernel/BasicPointFunctors.h"
42 
43 using namespace std;
44 using namespace DGtal;
45 using namespace Z2i;
46 
47 
48 
49 int main(int argc, char ** argv)
50 {
51 
54 
55  if(argc < 3)
56  {
57  trace.error() << "You need to indicate the volumetric image name and slice number as parameters." << std::endl;
58  trace.error() << std::endl;
59  return 1;
60  }
61  std::string filename(argv[1]);
62  std::string outputFileName = "sliceImage.pgm";
63 
64  unsigned int numSlice = atoi(argv[2]);
65 
66  trace.beginBlock("Loading file");
67  Image3D image3d = GenericReader< Image3D >::import ( filename );
68 
69 
72  Image3D::Value, functors::Identity > SliceImageAdapter;
74  Z2i::Domain domain2D(proj(image3d.domain().lowerBound()),
75  proj(image3d.domain().upperBound()));
76 
77  DGtal::functors::Projector<Z3i::Space> aSliceFunctor(numSlice);
78  aSliceFunctor.initAddOneDim(2);
79  SliceImageAdapter sliceImageZ(image3d, domain2D, aSliceFunctor, id);
80 
81  trace.endBlock();
82 
83  trace.beginBlock("Exporting...");
84  sliceImageZ >> outputFileName;
85  trace.endBlock();
86  return 0;
87 }
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
std::ostream & error()
void beginBlock(const std::string &keyword="")
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
Aim: Define a simple default functor that just returns its argument.
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
int main(int argc, char **argv)