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