DGtal  1.3.beta
images/extract2DSlicesImagesFrom3D.cpp

Example of 2D slice images extraction from 3D images.

Example of resulting 2D slices images of the sample/lobster.vol file.
#include <iostream>
#include <sstream>
#include "DGtal/kernel/BasicPointFunctors.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/PGMWriter.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "ConfigExamples.h"
using namespace std;
using namespace DGtal;
int main( )
{
// Importing a 3D image
std::string filename = examplesPath + "samples/lobster.vol";
Image3D image = VolReader<Image3D>::importVol( filename );
DGtal::Z2i::Domain domain(proj(image.domain().lowerBound()),
proj(image.domain().upperBound()));
trace.beginBlock ( "Example extract2DImagesFrom3D" );
// Extracting 2D slices ... and export them in the pgm format.
for (unsigned int i=0; i<30; i+=10){
std::stringstream name;
name << "lobsterSliceZ_" << i << ".pgm";
DGtal::functors::Projector<Z3i::Space> aSliceFunctor(i); aSliceFunctor.initAddOneDim(2);
SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
PGMWriter<SliceImageAdapter>::exportPGM(name.str(), sliceImageZ);
}
// trace.endBlock();
return 0;
}
// //
DGtal::functors::Projector
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Definition: BasicPointFunctors.h:106
DGtal::HyperRectDomain< Space >
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::PGMWriter
Aim: Export a 2D and a 3D Image using the Netpbm PGM formats (ASCII mode).
Definition: PGMWriter.h:88
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
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
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::functors::Projector::initAddOneDim
void initAddOneDim(const Dimension &newDim)
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38