DGtal  0.9.4beta
images/extract2DImagesFrom3DandVisu.cpp

Example of 2D images extraction from 3D images and 3D visualisation.

lobsterVisu3DSlicesZ.png
Example of 3D visualisation of 2D slices images of the sample/lobster.vol file.
#include <iostream>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageHelper.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "ConfigExamples.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/kernel/BasicPointFunctors.h"
using namespace std;
using namespace DGtal;
int main( int argc, char** argv )
{
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.setWindowTitle("simpleViewer");
viewer.show();
Image3D::Value, DGtal::functors::Identity > SliceImageAdapter;
Image3D::Value, DGtal::functors::Identity > ImageAdapterExtractor;
// Importing a 3D image
std::string filename = examplesPath + "samples/lobster.vol";
Image3D image = VolReader<Image3D>::importVol( filename );
DGtal::Z2i::Domain domain(invFunctor(image.domain().lowerBound()),
invFunctor(image.domain().upperBound()));
trace.beginBlock ( "Example extract2DImagesFrom3D" );
// Extracting 2D slices ... and visualisation on 3DViewer
unsigned int pos=0;
for (unsigned int i=0; i<30; i+=5){
SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
viewer << sliceImageZ;
viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(pos, Viewer3D<>::zDirection, i*20, i*20, i*20 );
pos++;
}
// Visu extraction from points
const int IMAGE_PATCH_WIDTH = 40;
DGtal::Z3i::Point ptCenter(155, 155, 20);
DGtal::Z2i::Point(IMAGE_PATCH_WIDTH, IMAGE_PATCH_WIDTH));
IMAGE_PATCH_WIDTH);
ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
viewer << extractedImage;
viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(pos,
embedder(Z2i::Point(0,0)),
embedder(Z2i::Point(IMAGE_PATCH_WIDTH,0)),
embedder(domainImage2D.upperBound()),
embedder(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH)));
viewer << DGtal::Viewer3D<>::updateDisplay;
application.exec();
return 0;
}
// //