DGtal  1.4.beta
images/imageBasicSubsampling.cpp

Examples of 2D and 3D basic image subsampling.

Illustration of the resulting subsampling produced by this example.
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/kernel/BasicPointFunctors.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/readers/GenericReader.h"
#include "DGtal/io/writers/GenericWriter.h"
using namespace std;
using namespace DGtal;
int main( int /*argc*/, char** /*argv*/ )
{
functors::Identity > ConstImageAdapterForSubSampling;
functors::Identity > ConstImageAdapterForSubSampling3D;
trace.beginBlock ( "Example imageBasicSubsampling" );
std::string imageFilename3D = examplesPath + "samples/Al.100.vol";
std::string imageFilename2D = examplesPath + "samples/church.pgm";
Image3D image3D = GenericReader<Image3D>::import( imageFilename3D );
Image2D image2D = GenericReader<Image2D>::import( imageFilename2D );
for (unsigned int i=1; i<=20; i*=2){
std::vector<Z2i::Domain::Size> aGridSize2D;
aGridSize2D.push_back(i);
aGridSize2D.push_back(i);
// Construction of the functor for the 2D domain subsampling from a given grid size and shift.
DGtal::functors::BasicDomainSubSampler<Image2D::Domain> subSampler2D(image2D.domain(), aGridSize2D, Z2i::Point(0 ,0));
// Get the new domain produces from the subsampler and define the ConstImageAdapter:
Image2D::Domain subSampledDomain2D = subSampler2D.getSubSampledDomain();
ConstImageAdapterForSubSampling subsampledImage2D (image2D, subSampledDomain2D, subSampler2D, df);
stringstream outputname;
outputname << "subSampledImage"<< i<< "x"<< i << ".pgm" ;
GenericWriter<ConstImageAdapterForSubSampling>::exportFile(outputname.str(), subsampledImage2D );
trace.info() << "Exporting 2D subsampled image by grid size :" << i << "x"<< i<< " in "<< outputname.str() << std::endl;
}
for (unsigned int i=1; i<=20; i*=2){
std::vector<Z3i::Domain::Size> aGridSize3D;
aGridSize3D.push_back(i);
aGridSize3D.push_back(i);
aGridSize3D.push_back(i);
// Construction of the functor for the 3D domain subsampling from a given grid size and shift.
DGtal::functors::BasicDomainSubSampler<Image3D::Domain> subSampler3D(image3D.domain(), aGridSize3D, Z3i::Point(0 ,0, 0));
// Get the new domain produces from the subsampler and define the ConstImageAdapter:
Image3D::Domain subSampledDomain3D = subSampler3D.getSubSampledDomain();
ConstImageAdapterForSubSampling3D subsampledImage3D (image3D, subSampledDomain3D, subSampler3D, df);
stringstream outputname3D;
outputname3D << "subSampledImage3D"<< i<< "x"<< i << ".vol" ;
GenericWriter<ConstImageAdapterForSubSampling3D>::exportFile(outputname3D.str(), subsampledImage3D );
trace.info() << "Exporting 3D subsampled image by grid size :" << i << "x"<< i<< "x"<< i<< " in "<< outputname3D.str() << std::endl;
}
return 0;
}
// //
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::GenericReader
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
Definition: GenericReader.h:99
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition: BasicFunctors.h:287
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition: ConstImageAdapter.h:105
DGtal::Trace::info
std::ostream & info()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::GenericWriter
Aim: Provide a mechanism to save image (2D or 3D) into file with the best saver loader according to a...
Definition: GenericWriter.h:94
DGtal::functors::BasicDomainSubSampler
Aim: Functor that subsamples an initial domain by given a grid size and a shift vector....
Definition: BasicPointFunctors.h:637
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::PointVector< dim, Integer >
DGtal::functors::BasicDomainSubSampler::getSubSampledDomain
const TDomain & getSubSampledDomain()
Definition: BasicPointFunctors.h:726
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38