DGtal  1.0.0
imageBasicSubsampling.cpp
Go to the documentation of this file.
1 
40 #include <iostream>
42 #include "ConfigExamples.h"
43 #include "DGtal/helpers/StdDefs.h"
44 #include "DGtal/base/Common.h"
45 
47 #include "DGtal/kernel/BasicPointFunctors.h"
48 #include "DGtal/images/ConstImageAdapter.h"
50 
51 #include "DGtal/images/ImageContainerBySTLVector.h"
52 
53 #include "DGtal/io/readers/GenericReader.h"
54 #include "DGtal/io/writers/GenericWriter.h"
55 
57 
58 using namespace std;
59 using namespace DGtal;
60 
62 
63 int main( int /*argc*/, char** /*argv*/ )
64 {
65 
68  typedef ConstImageAdapter<Image2D, Image2D::Domain,
71  functors::Identity > ConstImageAdapterForSubSampling;
72 
74 
77  typedef ConstImageAdapter<Image3D, Image3D::Domain,
80  functors::Identity > ConstImageAdapterForSubSampling3D;
82 
83 
84  trace.beginBlock ( "Example imageBasicSubsampling" );
85 
86  std::string imageFilename3D = examplesPath + "samples/Al.100.vol";
87  std::string imageFilename2D = examplesPath + "samples/church.pgm";
88  Image3D image3D = GenericReader<Image3D>::import( imageFilename3D );
89  Image2D image2D = GenericReader<Image2D>::import( imageFilename2D );
90 
91  for (unsigned int i=1; i<=20; i*=2){
92  std::vector<Z2i::Domain::Size> aGridSize2D;
93  aGridSize2D.push_back(i);
94  aGridSize2D.push_back(i);
95  // Construction of the functor for the 2D domain subsampling from a given grid size and shift.
97  DGtal::functors::BasicDomainSubSampler<Image2D::Domain> subSampler2D(image2D.domain(), aGridSize2D, Z2i::Point(0 ,0));
99 
101  // Get the new domain produces from the subsampler and define the ConstImageAdapter:
103  Image2D::Domain subSampledDomain2D = subSampler2D.getSubSampledDomain();
104  ConstImageAdapterForSubSampling subsampledImage2D (image2D, subSampledDomain2D, subSampler2D, df);
106 
107  stringstream outputname;
108  outputname << "subSampledImage"<< i<< "x"<< i << ".pgm" ;
110  GenericWriter<ConstImageAdapterForSubSampling>::exportFile(outputname.str(), subsampledImage2D );
112  trace.info() << "Exporting 2D subsampled image by grid size :" << i << "x"<< i<< " in "<< outputname.str() << std::endl;
113  }
114 
115  for (unsigned int i=1; i<=20; i*=2){
116  std::vector<Z3i::Domain::Size> aGridSize3D;
117  aGridSize3D.push_back(i);
118  aGridSize3D.push_back(i);
119  aGridSize3D.push_back(i);
120 
121  // Construction of the functor for the 3D domain subsampling from a given grid size and shift.
123  DGtal::functors::BasicDomainSubSampler<Image3D::Domain> subSampler3D(image3D.domain(), aGridSize3D, Z3i::Point(0 ,0, 0));
125 
127  // Get the new domain produces from the subsampler and define the ConstImageAdapter:
129  Image3D::Domain subSampledDomain3D = subSampler3D.getSubSampledDomain();
130  ConstImageAdapterForSubSampling3D subsampledImage3D (image3D, subSampledDomain3D, subSampler3D, df);
132 
133  stringstream outputname3D;
134  outputname3D << "subSampledImage3D"<< i<< "x"<< i << ".vol" ;
136  GenericWriter<ConstImageAdapterForSubSampling3D>::exportFile(outputname3D.str(), subsampledImage3D );
138  trace.info() << "Exporting 3D subsampled image by grid size :" << i << "x"<< i<< "x"<< i<< " in "<< outputname3D.str() << std::endl;
139  }
140 
141 
142  trace.endBlock();
143  return 0;
144 }
145 // //
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Trace trace
Definition: Common.h:144
double endBlock()
int main(int, char **)
Aim: Functor that subsamples an initial domain by given a grid size and a shift vector....
Aim: Provide a mechanism to save image (2D or 3D) into file with the best saver loader according to a...
Definition: GenericWriter.h:93
Aim: Define a simple default functor that just returns its argument.
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...