Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
erosion.hh
1 // Copyright (C) 2007, 2008, 2009 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 
27 #ifndef MLN_MORPHO_EROSION_HH
28 # define MLN_MORPHO_EROSION_HH
29 
35 
36 # include <mln/morpho/general.hh>
37 # include <mln/morpho/includes.hh>
38 # include <mln/accu/logic/land.hh>
39 # include <mln/accu/logic/land_basic.hh>
40 # include <mln/accu/stat/min.hh>
41 # include <mln/accu/stat/min_h.hh>
42 
43 
44 namespace mln
45 {
46 
47  namespace morpho
48  {
49 
51  template <typename I, typename W>
52  mln_concrete(I)
53  erosion(const Image<I>& input, const Window<W>& win);
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58  struct erosion_op
59  {
60 
61  template <typename I>
62  mln_morpho_select_accu(I, logic::land_basic, stat::min)
63  accu(const Image<I>&) const
64  {
65  mln_morpho_select_accu(I, logic::land_basic, stat::min) tmp;
66  return tmp;
67  }
68 
69  template <typename I>
70  mln_morpho_select_accu(I, logic::land, stat::min_h)
71  accu_incr(const Image<I>&) const
72  {
73  mln_morpho_select_accu(I, logic::land, stat::min_h) tmp;
74  return tmp;
75  }
76 
77  template <typename I>
78  mln_value(I) neutral(const Image<I>&) const
79  {
80  return internal::neutral<I>::supremum();
81  }
82 
83  };
84 
85 
86  namespace impl
87  {
88 
89 
90  // On set with centered window (overloads).
91 
92  template <typename I, typename W>
93  mln_concrete(I)
94  general_on_set_centered(const erosion_op&,
95  const Image<I>& input_, const Window<W>& win_)
96  {
97  trace::entering("morpho::impl::general_on_set_centered__erosion");
98 
99  typedef mln_concrete(I) O;
100  const I& input = exact(input_);
101  const W& win = exact(win_);
102 
103  extension::adjust_fill(input, win, true);
104 
105  O output;
106  output = duplicate(input);
107 
108  mln_piter(I) p(input.domain());
109  mln_qiter(W) q(win, p);
110  for_all(p)
111  if (input(p) == true)
112  for_all(q) if (input.has(q))
113  if (input(q) == false)
114  {
115  output(p) = false;
116  break;
117  }
118 
119  trace::exiting("morpho::impl::general_on_set_centered__erosion");
120  return output;
121  }
122 
123 
124  template <typename I, typename W>
125  mln_concrete(I)
126  general_on_set_centered_fastest(const erosion_op&,
127  const Image<I>& input_, const Window<W>& win_)
128  {
129  trace::entering("morpho::impl::general_on_set_centered_fastest__erosion");
130 
131  typedef mln_concrete(I) O;
132  const I& input = exact(input_);
133  const W& win = exact(win_);
134 
135  extension::adjust_fill(input, win, true);
136 
137  O output;
138  output = duplicate(input);
139 
140  mln_pixter(const I) p(input);
141  mln_qixter(const I, W) q(p, win);
142  mln_pixter(O) p_out(output);
143  for_all_2(p, p_out)
144  if (p.val() == true)
145  for_all(q)
146  if (q.val() == false)
147  {
148  p_out.val() = false;
149  break;
150  }
151 
152  trace::exiting("morpho::impl::general_on_set_centered_fastest__erosion");
153  return output;
154  }
155 
156  } // end of namespace morpho::impl
157 
158 
159 
160  template <typename I, typename W>
161  inline
162  mln_concrete(I)
163  erosion(const Image<I>& input, const Window<W>& win)
164  {
165  trace::entering("morpho::erosion");
166  mln_precondition(exact(input).is_valid());
167  mln_precondition(! exact(win).is_empty());
168 
169  mln_concrete(I) output = general(erosion_op(), input, win);
170 
171  if (exact(win).is_centered())
172  mln_postcondition(output <= input);
173 
174  trace::exiting("morpho::erosion");
175  return output;
176  }
177 
178 # endif // ! MLN_INCLUDE_ONLY
179 
180  } // end of namespace mln::morpho
181 
182 } // end of namespace mln
183 
184 
185 #endif // ! MLN_MORPHO_EROSION_HH