$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
line_graph_image_morpho.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 
30 
31 // FIXME: Rename as edge_image_morpho.hh.
32 
33 #include <mln/core/alias/point2d.hh>
34 
35 #include <mln/util/graph.hh>
36 #include <mln/fun/i2v/array.hh>
37 #include <mln/util/site_pair.hh>
38 #include <mln/core/image/edge_image.hh>
39 
40 #include <mln/morpho/erosion.hh>
41 #include <mln/morpho/dilation.hh>
42 
43 
44 int main()
45 {
46  using namespace mln;
47 
48  /*--------.
49  | Graph. |
50  `--------*/
51 
52  /* The graph and its corresponding line graph are as follows:
53 
54  0 1 2 3 4 0 1 2 3 4
55  .----------- .-----------
56  | |
57  0 | 0 2 0 | * *
58  1 | \ / | 1 | 0 1 |
59  2 | 1 | 2 | * 4
60  3 | \ | 3 | 2 |
61  4 | 3-4 4 | *3*
62 
63  Numbers in the graph represent the vertices and edges identifers
64  (resp.). */
65 
66  // Graph.
67  util::graph g;
68 
69  // Populate the graph with 5 vertices.
70  g.add_vertices(5);
71 
72  // Populate the graph with edges.
73  g.add_edge(0, 1);
74  g.add_edge(1, 2);
75  g.add_edge(1, 3);
76  g.add_edge(3, 4);
77  g.add_edge(4, 2);
78 
79  // Sites (points) associated to edges.
80  typedef util::site_pair<point2d> P;
81  typedef fun::i2v::array<P> fsite_t;
82  fsite_t sites(5);
83  sites(0) = P(point2d(0,0), point2d(2,2)); // Site associated to edge 0.
84  sites(1) = P(point2d(2,2), point2d(0,4)); // Site associated to edge 1.
85  sites(2) = P(point2d(2,2), point2d(4,3)); // Site associated to edge 2.
86  sites(3) = P(point2d(4,3), point2d(4,4)); // Site associated to edge 3.
87  sites(4) = P(point2d(0,4), point2d(4,4)); // Site associated to edge 4.
88 
89  /*-------------------.
90  | Line graph image. |
91  `-------------------*/
92 
93  // Line graph values.
94  typedef fun::i2v::array<unsigned> viota_t;
95  viota_t iota(g.v_nmax());
96  for (unsigned i = 0; i < iota.size(); ++i)
97  iota(i) = 10 + i;
98 
100  ima_t ima(g, sites, iota);
101 
102  /*-------------------------------.
103  | Processing line graph images. |
104  `-------------------------------*/
105 
106  // Elementary window of an edge.
107  ima_t::win_t win;
108  unsigned i = 0;
109 
110  // Reference values.
111  const unsigned dil_ref[] = { 12, 14, 13, 14, 13 };
112  const unsigned ero_ref[] = { 11, 10, 10, 12, 11 };
113 
114  ima_t ima_dil = morpho::dilation(ima, win);
115  // Manual iteration over the domain of IMA_DIL.
116  mln_piter_(ima_t) p_dil(ima_dil.domain());
117  for_all (p_dil)
118  mln_assertion(dil_ref[i++] == ima_dil(p_dil));
119 
120  ima_t ima_ero = morpho::erosion(ima, win);
121  // Manual iteration over the domain of IMA_ERO.
122  mln_piter_(ima_t) p_ero(ima_ero.domain());
123  i = 0;
124  for_all (p_ero)
125  mln_assertion(ero_ref[i++] == ima_ero(p_ero));
126 }