$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
graph_image_wst.cc
1
// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
2
// Laboratory (LRDE)
3
//
4
// This file is part of Olena.
5
//
6
// Olena is free software: you can redistribute it and/or modify it under
7
// the terms of the GNU General Public License as published by the Free
8
// Software Foundation, version 2 of the License.
9
//
10
// Olena is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
17
//
18
// As a special exception, you may use this file as part of a free
19
// software project without restriction. Specifically, if other files
20
// instantiate templates or use macros or inline functions from this
21
// file, or you compile this file and link it with other files to produce
22
// an executable, this file does not by itself cause the resulting
23
// executable to be covered by the GNU General Public License. This
24
// exception does not however invalidate any other reasons why the
25
// executable file might be covered by the GNU General Public License.
26
29
30
#include <vector>
31
32
#include <mln/util/graph.hh>
33
#include <mln/fun/i2v/array.hh>
34
#include <mln/core/alias/point2d.hh>
35
#include <mln/core/image/vertex_image.hh>
36
#include <mln/make/vertex_image.hh>
37
38
#include <mln/morpho/watershed/flooding.hh>
39
40
41
int
main()
42
{
43
using namespace
mln;
44
45
/*--------.
46
| Graph. |
47
`--------*/
48
49
/* The graph is as follows:
50
51
0 1 2 3 4
52
.-----------
53
|
54
0 | 0 2
55
1 | \ / |
56
2 | 1 |
57
3 | \ |
58
4 | 3-0
59
60
*/
61
62
// Points associated to vertices.
63
typedef
fun::i2v::array<point2d>
fsite_t;
64
fsite_t sites(5);
65
sites(0) =
point2d
(0,0);
// Point associated to vertex 0.
66
sites(1) =
point2d
(2,2);
// Point associated to vertex 1.
67
sites(2) =
point2d
(0,4);
// Point associated to vertex 2.
68
sites(3) =
point2d
(4,3);
// Point associated to vertex 3.
69
sites(4) =
point2d
(4,4);
// Point associated to vertex 4.
70
71
// Graph.
72
util::graph
g;
73
74
// Populate the graph with vertices.
75
g.
add_vertices
(sites.size());
76
77
// Populate the graph with edges.
78
g.add_edge(0, 1);
79
g.add_edge(1, 2);
80
g.add_edge(1, 3);
81
g.add_edge(3, 4);
82
g.add_edge(4, 2);
83
84
/*-------------.
85
| Graph image. |
86
`-------------*/
87
88
// Graph values.
89
typedef
fun::i2v::array<unsigned>
viota_t;
90
viota_t
iota
(g.v_nmax());
91
for
(
unsigned
i = 0; i <
iota
.size(); ++i)
92
iota
(i) = 10 + i;
93
94
typedef
vertex_image<point2d, unsigned, util::graph>
ima_t;
95
ima_t ima =
make::vertex_image
(g, sites,
iota
);
96
97
/*------.
98
| WST. |
99
`------*/
100
101
// Elementary neighborhood of a vertex.
102
typedef
ima_t::nbh_t nbh_t;
103
nbh_t
nbh
;
104
105
unsigned
nbasins;
106
ima_t wshed =
morpho::watershed::flooding
(ima, nbh, nbasins);
107
std::cout <<
"nbasins = "
<< nbasins << std::endl;
108
109
// Manual iteration over the domain of WSHED.
110
mln_piter_(ima_t) pw(wshed.domain());
111
for_all (pw)
112
std::cout << "wshed (" << pw << ") = " << wshed(pw) << std::endl;
113
}
tests
morpho
graph_image_wst.cc
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)