DGtal  1.3.beta
images/extract2DImagesFrom3D.cpp

Example of 2D images extraction from 3D images.

Example of one of the resulting

2D images of the sample/lobster.vol file (with increased size)."

#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;
const int IMAGE_PATCH_WIDTH = 70;
int main( int /*argc*/, char** /*argv*/ )
{
Image3D::Value, DGtal::functors::Identity > ImageAdapterExtractor;
DGtal::Z3i::Point origin(150, 150, 10);
DGtal::Z3i::Point ptUpper1(220, 220, 10);
DGtal::Z3i::Point ptUpper2(150, 150, 50);
DGtal::Z2i::Point(static_cast<int>((ptUpper1-origin).norm()),
static_cast<int>((ptUpper2-origin).norm())));
DGtal::Z3i::Point ptCenter(175, 175, 20);
DGtal::Z2i::Domain domainImage2D2 (DGtal::Z2i::Point(0,0),
// Importing a 3D image
std::string filename = examplesPath + "samples/lobster.vol";
Image3D image = VolReader<Image3D>::importVol( filename );
DGtal::Z3i::Domain domainImage3D = image.domain();
trace.beginBlock ( "Example extract2DImagesFrom3D" );
// Extracting 2D images ... and export them in the pgm format.
for (unsigned int i=0; i<30; i+=10){
std::stringstream name;
name << "lobsterExtracted_" << i << ".pgm";
std::stringstream name2;
name2 << "lobsterExtracted_" << i << "V2.pgm";
ptUpper1+DGtal::Z3i::Point(i,i,0),
ptUpper2+DGtal::Z3i::Point(i,i,0));
ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
ImageAdapterExtractor extractedImage2(image, domainImage2D2, embedder2, idV);
PGMWriter< ImageAdapterExtractor>::exportPGM(name.str(), extractedImage);
PGMWriter< ImageAdapterExtractor>::exportPGM(name2.str(), extractedImage2);
}
// trace.endBlock();
return 0;
}
// //
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.
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::PointVector< dim, Integer >
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
IMAGE_PATCH_WIDTH
const int IMAGE_PATCH_WIDTH
Definition: extract2DImagesFrom3D.cpp:59
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::functors::Point2DEmbedderIn3D
Aim: Functor that embeds a 2D point into a 3D space from two axis vectors and an origin point given i...
Definition: BasicPointFunctors.h:372