DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleArrayImageAdapter.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
33
#include <DGtal/base/Common.h>
34
#include <DGtal/helpers/StdDefs.h>
35
36
#include <DGtal/io/boards/Board2D.h>
37
39
#include <new>
40
#include <cmath>
41
#include <algorithm>
42
#include <DGtal/io/colormaps/HueShadeColorMap.h>
43
#include <DGtal/images/ImageContainerBySTLVector.h>
44
#include <DGtal/images/ArrayImageAdapter.h>
46
48
using namespace
std
;
49
using namespace
DGtal
;
51
52
void
ArrayImageAdapter_example
()
53
{
55
using
Space
=
SpaceND<2>
;
56
using
Domain
=
HyperRectDomain<Space>
;
57
using
Point
=
Domain::Point
;
58
using
Value
= double;
59
60
const
Domain
domain
(
Point
(0, 1),
Point
(4, 3) );
61
62
Value
* data =
new
Value
[
domain
.size() ];
63
64
// Convert this allocated memory to a CImage model.
65
ArrayImageAdapter< Value*, Domain >
image
( data,
domain
);
66
// Alternative syntax using the helpers:
67
// auto image = makeArrayImageAdapterFromIterator( data, domain );
68
69
// Fill the image with first coordinate of the point
70
for
(
auto
it =
image
.begin(); it !=
image
.end(); ++it )
71
{
72
*it = it.getPoint()[0];
73
}
74
75
// Get a constant view on a sub-domain.
76
const
Domain
sub_domain(
Point
(1, 1),
Point
(3, 2) );
77
ArrayImageAdapter< Value const*, Domain > cst_image( data,
domain
, sub_domain );
78
// Alternative syntax using the helpers:
79
// auto const cst_image = makeArrayImageAdapterFromImage( image, sub_domain );
80
81
// Display it.
82
for
(
auto
value : cst_image )
83
{
84
std::cout << value <<
" "
;
85
}
86
std::cout << std::endl;
88
}
89
90
void
moduleImages_example
()
91
{
92
using namespace
Z2i
;
93
94
Board2D
aBoard;
95
97
using
Value
= double;
// value type of the image
98
using
HueShadeDouble =
HueShadeColorMap<Value>
;
// a simple HueShadeColorMap varying on 'double' values
100
101
trace
.
beginBlock
(
"image"
);
102
104
const
Domain
domain
(
Point
(1,1),
Point
(16,16));
105
Value
* data =
new
Value
[
domain
.size() ];
106
ArrayImageAdapter< Value*, Domain >
image
( data,
domain
);
108
110
Value
i = 0;
111
for
(
auto
& value :
image
)
112
value = i++;
114
115
aBoard.
clear
();
116
Display2DFactory::drawImage<HueShadeDouble>
(aBoard,
image
, 0,
domain
.size()-1);
117
aBoard.
saveSVG
(
"ArrayImageAdapter_image.svg"
);
118
119
trace
.
endBlock
();
120
121
trace
.
beginBlock
(
"subImage"
);
122
124
Domain
subDomain(
Point
(1,1),
Point
(8,8));
125
ArrayImageAdapter< Value const*, Domain > constSubImage( data,
domain
, subDomain );
127
128
aBoard.
clear
();
129
Display2DFactory::drawImage<HueShadeDouble>
(aBoard, constSubImage, 0,
domain
.size()-1);
130
aBoard.
saveSVG
(
"ArrayImageAdapter_subImage.svg"
);
131
132
trace
.
endBlock
();
133
134
trace
.
beginBlock
(
"modifying subImage through domain iterator"
);
135
{
137
ArrayImageAdapter< Value*, Domain > subImage( data,
domain
, subDomain );
139
}
140
142
auto
subImage =
makeArrayImageAdapterFromIterator
( data,
domain
, subDomain );
144
145
147
for
(
auto
point : subImage.domain() )
148
{
149
Value
coord = (point -
Point
(4,4)).norm();
150
subImage.setValue( point, 25*(cos(coord)+1) );
151
}
153
154
aBoard.
clear
();
155
Display2DFactory::drawImage<HueShadeDouble>
(aBoard,
image
, 0,
domain
.size()-1);
156
aBoard.
saveSVG
(
"ArrayImageAdapter_subImage_modifByDomain.svg"
);
157
158
trace
.
endBlock
();
159
160
trace
.
beginBlock
(
"modifying subImage through image iterator"
);
162
for
(
auto
it = subImage.begin(), it_end = subImage.end(); it != it_end; ++it )
163
{
164
Value
coord = (it.getPoint() -
Point
(4,4)).norm();
165
*it = 25*(sin(coord)+1);
166
}
168
169
aBoard.
clear
();
170
Display2DFactory::drawImage<HueShadeDouble>
(aBoard,
image
, 0,
domain
.size()-1);
171
aBoard.
saveSVG
(
"ArrayImageAdapter_subImage_modifByImage.svg"
);
172
173
trace
.
endBlock
();
174
175
trace
.
beginBlock
(
"subImage from an ImageContainerBySTLVector"
);
177
ImageContainerBySTLVector<Domain, Value>
anIterableImage(
domain
);
178
for
(
auto
& value : anIterableImage)
179
value = 0;
181
183
{
184
ArrayImageAdapter< ImageContainerBySTLVector<Domain,Value>::Iterator,
Domain
> subImageSTL( anIterableImage.begin(),
domain
, subDomain );
185
}
187
189
auto
subImageSTL =
makeArrayImageAdapterFromImage
( anIterableImage, subDomain );
191
192
trace
.
endBlock
();
193
194
trace
.
beginBlock
(
"using std::copy on ArrayImageAdapter"
);
196
std::copy( subImage.cbegin(), subImage.cend(), subImageSTL.begin() );
198
199
aBoard.
clear
();
200
Display2DFactory::drawImage<HueShadeDouble>
(aBoard, anIterableImage, 0,
domain
.size()-1);
201
aBoard.
saveSVG
(
"ArrayImageAdapter_subImage_copyToImageSTL.svg"
);
202
203
trace
.
endBlock
();
204
205
delete
[] data;
206
}
207
208
int
main
()
209
{
210
ArrayImageAdapter_example
();
211
moduleImages_example
();
212
return
0;
213
}
214
215
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain< Space >::Point
Space::Point Point
Definition
HyperRectDomain.h:113
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::SpaceND
Definition
SpaceND.h:96
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition
Board.cpp:151
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
moduleImages_example
void moduleImages_example()
Definition
exampleArrayImageAdapter.cpp:90
ArrayImageAdapter_example
void ArrayImageAdapter_example()
Definition
exampleArrayImageAdapter.cpp:52
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::makeArrayImageAdapterFromIterator
ArrayImageAdapter< TArrayIterator, TDomain > makeArrayImageAdapterFromIterator(TArrayIterator anArrayIterator, TDomain const &aFullDomain, TDomain const &aViewDomain)
Definition
ArrayImageAdapter.h:465
DGtal::makeArrayImageAdapterFromImage
ArrayImageAdapter< decltype(((TImage *) nullptr) ->begin()), TDomain > makeArrayImageAdapterFromImage(TImage &anImage, TDomain const &aViewDomain)
Definition
ArrayImageAdapter.h:500
DGtal::trace
Trace trace
std
STL namespace.
DGtal::Space
DGtal::Display2DFactory::drawImage
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
DGtal::Value
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
image
Image image(domain)
examples
images
exampleArrayImageAdapter.cpp
Generated on
for DGtal by
1.18.0