DGtal
2.1.0
Loading...
Searching...
No Matches
2DSliceImageFromVol.cpp
Go to the documentation of this file.
1
31
#include <iostream>
32
#include <DGtal/base/Common.h>
33
#include "DGtal/io/readers/GenericReader.h"
34
#include "DGtal/io/writers/GenericWriter.h"
35
36
#include <DGtal/helpers/StdDefs.h>
37
#include <DGtal/images/ImageContainerBySTLVector.h>
38
#include <DGtal/images/ConstImageAdapter.h>
39
40
41
#include "DGtal/kernel/BasicPointFunctors.h"
42
43
using namespace
std
;
44
using namespace
DGtal
;
45
using namespace
Z2i;
46
47
48
49
int
main
(
int
argc,
char
** argv)
50
{
51
52
typedef
ImageContainerBySTLVector<Z2i::Domain, unsigned char>
Image2D;
53
typedef
ImageContainerBySTLVector<Z3i::Domain, unsigned char>
Image3D;
54
55
if
(argc < 3)
56
{
57
trace
.
error
() <<
"You need to indicate the volumetric image name and slice number as parameters."
<< std::endl;
58
trace
.
error
() << std::endl;
59
return
1;
60
}
61
std::string filename(argv[1]);
62
std::string outputFileName =
"sliceImage.pgm"
;
63
64
unsigned
int
numSlice = atoi(argv[2]);
65
66
trace
.
beginBlock
(
"Loading file"
);
67
Image3D image3d =
GenericReader< Image3D >::import
( filename );
68
69
70
functors::Identity
id;
71
typedef
ConstImageAdapter<Image3D, Image2D::Domain, functors::Projector<Z3i::Space>
,
72
Image3D::Value,
functors::Identity
> SliceImageAdapter;
73
functors::Projector<Z2i::Space >
proj(2);
74
Z2i::Domain
domain2D(proj(image3d.domain().lowerBound()),
75
proj(image3d.domain().upperBound()));
76
77
DGtal::functors::Projector<Z3i::Space>
aSliceFunctor(numSlice);
78
aSliceFunctor.
initAddOneDim
(2);
79
SliceImageAdapter sliceImageZ(image3d, domain2D, aSliceFunctor,
id
);
80
81
trace
.
endBlock
();
82
83
trace
.
beginBlock
(
"Exporting..."
);
84
sliceImageZ >> outputFileName;
85
trace
.
endBlock
();
86
return
0;
87
}
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:106
DGtal::HyperRectDomain< Space >
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::error
std::ostream & error()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::GenericReader::import
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition
BasicFunctors.h:288
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:107
DGtal::functors::Projector::initAddOneDim
void initAddOneDim(const Dimension &newDim)
main
int main()
Definition
testBits.cpp:56
examples
tutorial-examples
2DSliceImageFromVol.cpp
Generated on Tue Aug 26 2025 14:27:43 for DGtal by
1.9.8