DGtal  0.9.2
extract2DSlicesImagesFrom3D.cpp
1 
30 #include <iostream>
32 #include <sstream>
33 #include "DGtal/kernel/BasicPointFunctors.h"
34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/io/readers/VolReader.h"
37 #include "DGtal/io/writers/PGMWriter.h"
38 #include "DGtal/images/ImageSelector.h"
39 #include "DGtal/images/ConstImageAdapter.h"
40 #include "ConfigExamples.h"
42 
43 using namespace std;
44 using namespace DGtal;
45 
47 
48 int main( )
49 {
53  Image3D::Value, DGtal::functors::Identity > SliceImageAdapter;
54 
55 
57 
58  // Importing a 3D image
59  std::string filename = examplesPath + "samples/lobster.vol";
60  Image3D image = VolReader<Image3D>::importVol( filename );
61  DGtal::Z2i::Domain domain(proj(image.domain().lowerBound()),
62  proj(image.domain().upperBound()));
64 
65  trace.beginBlock ( "Example extract2DImagesFrom3D" );
66 
67  // Extracting 2D slices ... and export them in the pgm format.
68  for (unsigned int i=0; i<30; i+=10){
69  std::stringstream name;
70  name << "lobsterSliceZ_" << i << ".pgm";
71  DGtal::functors::Projector<Z3i::Space> aSliceFunctor(i); aSliceFunctor.initAddOneDim(2);
72  SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
73  PGMWriter<SliceImageAdapter>::exportPGM(name.str(), sliceImageZ);
74  }
75 
76  // trace.endBlock();
77  return 0;
78 }
79 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Aim: Define a simple default functor that just returns its argument.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Export a 2D and a 3D Image using the Netpbm PGM formats (ASCII mode).
Definition: PGMWriter.h:88
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...