Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
thinning.hh
1 // Copyright (C) 2007, 2008, 2009 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 
26 #ifndef MLN_MORPHO_THINNING_HH
27 # define MLN_MORPHO_THINNING_HH
28 
32 
33 # include <mln/morpho/hit_or_miss.hh>
34 # include <mln/morpho/thickening.hh>
35 
36 #include <mln/io/pgm/save.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace morpho
43  {
44 
45 
49  //
50  template <typename I, typename Wfg, typename Wbg>
51  mln_concrete(I)
52  thinning(const Image<I>& input,
53  const Window<Wfg>& win_fg, const Window<Wbg>& win_bg);
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58  namespace internal
59  {
60 
61  template <typename I, typename Wfg, typename Wbg>
62  inline
63  void
64  thinning_tests(const Image<I>& input_,
65  const Window<Wfg>& win_fg_,
66  const Window<Wbg>& win_bg_)
67  {
68  const I& input = exact(input_);
69  const Wfg& win_fg = exact(win_fg_);
70  const Wbg& win_bg = exact(win_bg_);
71 
72  // Tests.
73  mln_precondition(input.is_valid());
74  mln_precondition(win_fg.is_centered());
75  mln_precondition(! win_bg.is_empty());
76  mln_precondition((win_fg && win_bg).is_empty());
77 
78  // Avoid warnings.
79  (void) input_;
80  (void) win_fg_;
81  (void) win_bg_;
82  }
83 
84  } // end of namespace mln::morpho::internal
85 
86 
87  template <typename I, typename Wfg, typename Wbg>
88  inline
89  mln_concrete(I)
90  thinning(const Image<I>& input,
91  const Window<Wfg>& win_fg, const Window<Wbg>& win_bg)
92  {
93  trace::entering("morpho::thinning");
94 
95 
96  internal::thinning_tests(input, win_fg, win_bg);
97 
98  mln_concrete(I) output = morpho::minus( input,
99  hit_or_miss(input, win_fg, win_bg) );
100 
101  mln_postcondition( complementation( thickening( complementation(input),
102  win_bg, win_fg ) ) == output);
103  trace::exiting("morpho::thinning");
104  return output;
105  }
106 
107 # endif // ! MLN_INCLUDE_ONLY
108 
109  } // end of namespace mln::morpho
110 
111 } // end of namespace mln
112 
113 
114 #endif // ! MLN_MORPHO_THINNING_HH