DGtal  0.9.2
extract2DImagesFrom3D.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 const int IMAGE_PATCH_WIDTH = 70;
49 
50 int main( int /*argc*/, char** /*argv*/ )
51 {
55  Image3D::Value, DGtal::functors::Identity > ImageAdapterExtractor;
57 
59  DGtal::Z3i::Point origin(150, 150, 10);
60  DGtal::Z3i::Point ptUpper1(220, 220, 10);
61  DGtal::Z3i::Point ptUpper2(150, 150, 50);
62  DGtal::Z2i::Domain domainImage2D (DGtal::Z2i::Point(0,0),
63  DGtal::Z2i::Point(static_cast<int>((ptUpper1-origin).norm()),
64  static_cast<int>((ptUpper2-origin).norm())));
66  DGtal::Z3i::Point ptCenter(175, 175, 20);
67  DGtal::Z2i::Domain domainImage2D2 (DGtal::Z2i::Point(0,0),
68  DGtal::Z2i::Point(IMAGE_PATCH_WIDTH, IMAGE_PATCH_WIDTH));
69 
70 
71  // Importing a 3D image
72  std::string filename = examplesPath + "samples/lobster.vol";
73  Image3D image = VolReader<Image3D>::importVol( filename );
74  DGtal::Z3i::Domain domainImage3D = image.domain();
76 
77  trace.beginBlock ( "Example extract2DImagesFrom3D" );
78 
79  // Extracting 2D images ... and export them in the pgm format.
80  for (unsigned int i=0; i<30; i+=10){
81  std::stringstream name;
82  name << "lobsterExtracted_" << i << ".pgm";
83  std::stringstream name2;
84  name2 << "lobsterExtracted_" << i << "V2.pgm";
85 
88  ptUpper1+DGtal::Z3i::Point(i,i,0),
89  ptUpper2+DGtal::Z3i::Point(i,i,0));
90 
91  ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
93 
96  DGtal::Z3i::RealPoint(1,-1,0),
97  IMAGE_PATCH_WIDTH);
98  ImageAdapterExtractor extractedImage2(image, domainImage2D2, embedder2, idV);
100 
101  PGMWriter< ImageAdapterExtractor>::exportPGM(name.str(), extractedImage);
102  PGMWriter< ImageAdapterExtractor>::exportPGM(name2.str(), extractedImage2);
103  }
104 
105  // trace.endBlock();
106  return 0;
107 }
108 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
Aim: Define a simple default functor that just returns its argument.
Aim: Functor that embeds a 2D point into a 3D space from two axis vectors and an origin point given i...
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...