DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
imageBasicSubsampling.cpp File Reference
#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"

Go to the source code of this file.

Functions

int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2014/05/21

An example file named imageBasicSubsampling.

This file is part of the DGtal library.

Definition in file imageBasicSubsampling.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

[imageBasicSubsamplingType2D]

[imageBasicSubsamplingType2D]

[imageBasicSubsamplingType3D]

[imageBasicSubsamplingType3D]

[imageBasicSubsamplingSubSampler2D]

[imageBasicSubsamplingSubSampler2D]

[imageBasicSubsamplingConstImageAdapterSubSampling2D]

[imageBasicSubsamplingConstImageAdapterSubSampling2D]

[imageBasicSubsamplingExport2D]

[imageBasicSubsamplingExport2D]

[imageBasicSubsamplingSubSampler3D]

[imageBasicSubsamplingSubSampler3D]

[imageBasicSubsamplingConstImageAdapterSubSampling3D]

[imageBasicSubsamplingConstImageAdapterSubSampling3D]

[imageBasicSubsamplingExport3D]

[imageBasicSubsamplingExport3D]

Definition at line 63 of file imageBasicSubsampling.cpp.

64{
65
67 typedef ImageContainerBySTLVector < Z2i::Domain, unsigned char> Image2D;
68 typedef ConstImageAdapter<Image2D, Image2D::Domain,
70 Image2D::Value,
71 functors::Identity > ConstImageAdapterForSubSampling;
72
74
76 typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char> Image3D;
77 typedef ConstImageAdapter<Image3D, Image3D::Domain,
79 Image3D::Value,
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}
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
Aim: Functor that subsamples an initial domain by given a grid size and a shift vector....
Trace trace
Definition: Common.h:154
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
Aim: Define a simple default functor that just returns its argument.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::GenericWriter< TContainer, Tdim, TValue, TFunctor >::exportFile(), DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::getSubSampledDomain(), DGtal::GenericReader< TContainer, Tdim, TValue >::import(), DGtal::Trace::info(), and DGtal::trace.