$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Milena
Getting started
API Reference Manual
All Classes
Examples
Demos
Publications
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
tuto4_genericity_and_algorithms.cc
1
// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
// Olena is free software: you can redistribute it and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, version 2 of the License.
8
//
9
// Olena is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
16
//
17
// As a special exception, you may use this file as part of a free
18
// software project without restriction. Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
// file, or you compile this file and link it with other files to produce
21
// an executable, this file does not by itself cause the resulting
22
// executable to be covered by the GNU General Public License. This
23
// exception does not however invalidate any other reasons why the
24
// executable file might be covered by the GNU General Public License.
25
27
28
#include <mln/core/image/image2d.hh>
29
#include <mln/core/image/dmorph/image_if.hh>
30
#include <mln/core/routine/duplicate.hh>
31
#include <mln/core/site_set/p_array.hh>
32
#include <mln/core/var.hh>
33
#include <mln/core/alias/neighb2d.hh>
34
35
#include <mln/binarization/binarization.hh>
36
37
#include <mln/fun/p2b/chess.hh>
38
39
#include <mln/accu/stat/max.hh>
40
41
#include <mln/geom/all.hh>
42
43
#include <mln/value/rgb8.hh>
44
#include <mln/value/label_8.hh>
45
46
#include <mln/opt/at.hh>
47
48
#include <mln/data/fill.hh>
49
50
#include <mln/pw/all.hh>
51
52
#include <mln/labeling/colorize.hh>
53
#include <mln/labeling/blobs.hh>
54
55
#include <mln/literal/colors.hh>
56
#include <mln/literal/max.hh>
57
58
59
#include <tests/data.hh>
60
#include <doc/tools/sample_utils.hh>
61
62
struct
keep_specific_colors :
public
mln::Function_v2b
<keep_specific_colors>
63
{
64
bool
operator()(
const
mln::value::rgb8
& v)
const
65
{
66
return
v.
green
() < 200u && v.
blue
() > 100u;
67
}
68
};
69
70
int
main()
71
{
72
using namespace
mln;
73
74
// \{
75
image2d<value::rgb8>
lena;
76
io::ppm::load
(lena, MLN_IMG_DIR
"/small.ppm"
);
77
// \}
78
79
80
image2d<value::rgb8>
lena_bak =
duplicate
(lena);
81
// \{
82
box2d
roi =
make::box2d
(20, 20, 39, 39);
83
// \}
84
// \{
85
data::fill
((lena | roi).rw(),
literal::green
);
86
// \}
87
doc::ppmsave
(lena,
"tuto4_genericity_and_algorithms"
);
88
89
90
91
92
lena =
duplicate
(lena_bak);
93
// \{
94
p_array<point2d>
arr;
95
for
(
def::coord
row =
geom::min_row
(lena); row <=
geom::max_row
(lena); ++row)
96
for
(
def::coord
col =
geom::min_row
(lena); col <=
geom::max_col
(lena); ++col)
97
if
(((row + col) % 2) == 0)
98
arr.
append
(
point2d
(row, col));
99
// \}
100
// \{
101
for
(
def::coord
row =
geom::min_row
(lena); row <=
geom::max_row
(lena); ++row)
102
for
(
def::coord
col =
geom::min_row
(lena); col <=
geom::max_col
(lena); ++col)
103
if
(((row + col) % 2) == 0)
104
opt::at
(lena, row, col) =
literal::green
;
105
// \}
106
// \{
107
data::fill
((lena |
fun::p2b::chess
()).rw(),
literal::green
);
108
// \}
109
doc::ppmsave
(lena,
"tuto4_genericity_and_algorithms"
);
110
111
112
113
114
lena =
duplicate
(lena_bak);
115
// \{
116
image2d<bool>
mask;
117
initialize
(mask, lena);
118
data::fill
(mask,
false
);
119
data::fill
((mask |
make::box2d
(10, 10, 14, 14)).rw(),
true
);
120
data::fill
((mask |
make::box2d
(25, 15, 29, 18)).rw(),
true
);
121
data::fill
((mask |
make::box2d
(50, 50, 54, 54)).rw(),
true
);
122
// \}
123
doc::pbmsave
(mask,
"tuto4_genericity_and_algorithms"
);
124
// \{
125
data::fill
((lena |
pw::value
(mask)).rw(),
literal::green
);
126
// \}
127
doc::ppmsave
(lena,
"tuto4_genericity_and_algorithms"
);
128
129
130
131
132
lena =
duplicate
(lena_bak);
133
// \{
134
image2d<bool>
lena_bw =
binarization::binarization
(lena, keep_specific_colors());
135
value::label_8
nlabels;
136
image2d<value::label_8>
label =
labeling::blobs
(lena_bw,
c8
(), nlabels);
137
// \}
138
doc::ppmsave
(
labeling::colorize
(
value::rgb8
(), label, nlabels),
"tuto4_genericity_and_algorithms"
);
139
140
// \{
141
data::fill
((lena | (
pw::value
(label) ==
pw::cst
(0u))).rw(),
literal::blue
);
142
// \}
143
doc::ppmsave
(lena,
"tuto4_genericity_and_algorithms"
);
144
145
146
147
148
// Disabled until thru_image/fun_image provide working read/write access.
149
//
150
// lena = duplicate(lena_bak);
151
// // \{
152
// data::fill(extract::green(lena).rw(), literal::max);
153
// // \}
154
// //FIXME: we would like to save the green component in rgb8.
155
// doc::pgmsave(extract::green(lena), "tuto4_genericity_and_algorithms");
156
// doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
157
//
158
//
159
//
160
//
161
// lena = duplicate(lena_bak);
162
// // \{
163
// mln_VAR(object, pw::value(label) == pw::cst(0u));
164
// data::fill((extract::green(lena).rw() | object).rw(), literal::max);
165
// // \}
166
// //FIXME: how to display an image which is not defined on a box!?
168
// doc::ppmsave(lena, "tuto4_genericity_and_algorithms");
169
170
}
doc
examples
tuto4_genericity_and_algorithms.cc
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)