Examples of 2D and 3D basic image subsampling.
#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;
{
typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char> Image2D;
functors::BasicDomainSubSampler<Image2D::Domain>,
functors::Identity > ConstImageAdapterForSubSampling;
typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char> Image3D;
functors::BasicDomainSubSampler<Image3D::Domain>,
functors::Identity > ConstImageAdapterForSubSampling3D;
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);
functors::Identity df;
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);
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;
}
void beginBlock(const std::string &keyword="")
Aim: Functor that subsamples an initial domain by given a grid size and a shift vector....
const TDomain & getSubSampledDomain()
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Define a simple default functor that just returns its argument.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain