$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
priority_driven_thinning_constrained.cc
1 // Copyright (C) 2010, 2011 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 
29 
30 #include <mln/core/image/image2d.hh>
31 #include <mln/core/alias/neighb2d.hh>
32 
33 #include <mln/topo/skeleton/priority_driven_thinning.hh>
34 
35 #include <mln/topo/is_simple_point2d.hh>
36 #include <mln/topo/detach_point.hh>
37 #include <mln/topo/is_not_end_point.hh>
38 
39 #include <mln/logical/not.hh>
40 #include <mln/arith/revert.hh>
41 #include <mln/transform/distance_geodesic.hh>
42 
43 #include <mln/io/pbm/all.hh>
44 
45 #include "tests/data.hh"
46 
47 
48 int main()
49 {
50  using namespace mln;
51 
52  typedef image2d<bool> I;
53  typedef neighb2d N;
54 
55  // Add a border of (at least) 1 pixel, to a guarantee a meaningful
56  // result of the computation of connectivity numbers (called within
57  // is_simple_2d); indeed, this computation always expects each pixel
58  // to have 8 neighboring sites.
60 
61  I input = io::pbm::load(MLN_IMG_DIR "/small.pbm");
62 
63  // FIXME: Use a dual neighborhood instead?
64 
65  // Foreground neighborhood.
66  neighb2d nbh_fg = c4();
67  // Background neighborhood.
68  neighb2d nbh_bg = c8();
69 
70  // Simplicity criterion functor.
71  topo::is_simple_point2d<I, N> is_simple(nbh_fg, nbh_bg);
72  // Simple point detach procedure.
73  topo::detach_point<I> detach;
74  // Constraint: do not collapse end points.
75  topo::is_not_end_point<I, N> constraint(nbh_fg, input);
76 
77  // Distance type.
78  typedef value::int_u8 D;
79  // Distance map type.
80  typedef image2d<D> M;
81 
82  // Compute a distance map on the objects (foreground) of the image,
83  // instead of the (usual) background.
84  M dmap = transform::distance_geodesic(logical::not_(input), nbh_fg,
85  mln_max(D));
86  // Create a priority function (actually, an image) using the inverse
87  // of the distance map.
88  M priority = arith::revert(dmap);
89 
90  I output = topo::skeleton::priority_driven_thinning(input, nbh_fg,
91  is_simple,
92  detach,
93  priority,
94  constraint);
95  io::pbm::save(output, "priority_driven_thinning_constrained-small.pbm");
96 }