Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
erosion_tolerant.hh
1 // Copyright (C) 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_EROSION_TOLERANT_HH
27 # define MLN_MORPHO_EROSION_TOLERANT_HH
28 
35 
36 # include <mln/accu/count_value.hh>
37 # include <mln/accu/logic/land.hh>
38 # include <mln/accu/logic/land_basic.hh>
39 # include <mln/accu/stat/min.hh>
40 # include <mln/accu/stat/min_h.hh>
41 # include <mln/accu/transform.hh>
42 # include <mln/morpho/general.hh>
43 # include <mln/morpho/includes.hh>
44 # include <mln/morpho/erosion.hh>
45 
46 namespace mln
47 {
48 
49  namespace morpho
50  {
51 
53  template <typename I, typename W>
54  mln_concrete(I)
55  erosion_tolerant(const Image<I>& input, const Window<W>& win,
56  unsigned rank);
57 
58 
59 # ifndef MLN_INCLUDE_ONLY
60 
61 
62  // Implementation
63 
64  namespace impl
65  {
66 
67  template <typename I, typename W>
68  mln_concrete(I)
69  erosion_tolerant_on_set(const Image<I>& input_,
70  const Window<W>& win_,
71  unsigned rank)
72  {
73  trace::entering("morpho::impl::erosion_tolerant_on_set");
74 
75  typedef mln_concrete(I) O;
76  const I& input = exact(input_);
77  const W& win = exact(win_);
78 
79  extension::adjust_fill(input, win, true);
80 
81  mln_ch_value(I, unsigned)
82  tmp = accu::transform(input,
83  accu::count_value<mln_value(I)>(false),
84  win);
85 
86  O output;
87  output = duplicate(input);
88 
89  mln_piter(I) p(input.domain());
90  for_all(p)
91  if (input(p) == true && tmp(p) >= rank)
92  output(p) = false;
93 
94  trace::exiting("morpho::impl::erosion_tolerant_on_set");
95  return output;
96  }
97 
98 
99 
100  template <typename I, typename W>
101  mln_concrete(I)
102  erosion_tolerant_on_set_fastest(const Image<I>& input_,
103  const Window<W>& win_,
104  unsigned rank)
105  {
106  trace::entering("morpho::impl::erosion_tolerant_on_set_fastest");
107 
108  typedef mln_concrete(I) O;
109  const I& input = exact(input_);
110  const W& win = exact(win_);
111 
112  extension::adjust_fill(input, win, true);
113 
114  typedef mln_ch_value(I, unsigned) tmp_t;
115  tmp_t tmp = accu::transform(input,
116  accu::count_value<mln_value(I)>(false),
117  win);
118 
119  O output;
120  output = duplicate(input);
121 
122  mln_pixter(const I) p(input);
123  for_all(p)
124  if (p.val() == true)
125  if (tmp.element(p.offset()) >= rank)
126  output.element(p.offset()) = false;
127 
128  trace::exiting("morpho::impl::erosion_tolerant_on_set_fastest");
129  return output;
130  }
131 
132  } // end of namespace morpho::impl
133 
134 
135 
136 
137  // Dispatch
138 
139  namespace internal
140  {
141 
142  template <typename I, typename W>
143  mln_concrete(I)
144  erosion_tolerant_dispatch(trait::image::kind::any,
145  trait::image::speed::any,
146  const I& input, const W& win, unsigned rank)
147  {
148  mlc_abort(I)::check();
149 
150  typedef mln_concrete(I) output_t;
151  return output_t();
152  }
153 
154 
155  template <typename I, typename W>
156  mln_concrete(I)
157  erosion_tolerant_dispatch(trait::image::kind::logic,
158  trait::image::speed::any,
159  const I& input, const W& win, unsigned rank)
160  {
161  return impl::erosion_tolerant_on_set(input,
162  win,
163  rank);
164  }
165 
166  template <typename I, typename W>
167  mln_concrete(I)
168  erosion_tolerant_dispatch(trait::image::kind::logic, // On sets.
169  trait::image::speed::fastest, // Fastest.
170  const I& input, const W& win, unsigned rank)
171  {
172  return impl::erosion_tolerant_on_set_fastest(input,
173  win,
174  rank);
175  }
176 
177 
178  template <typename I, typename W>
179  inline
180  mln_concrete(I)
181  erosion_tolerant_dispatch(const Image<I>& input,
182  const Window<W>& win,
183  unsigned rank)
184  {
185  return erosion_tolerant_dispatch(mln_trait_image_kind(I)(),
186  mln_trait_image_speed(I)(),
187  exact(input), exact(win), rank);
188  }
189 
190  } // end of namespace mln::morpho::internal
191 
192 
193 
194 
195  // Facade
196 
197  template <typename I, typename W>
198  inline
199  mln_concrete(I)
200  erosion_tolerant(const Image<I>& input, const Window<W>& win,
201  unsigned rank)
202  {
203  trace::entering("morpho::erosion_tolerant");
204  mln_precondition(exact(input).is_valid());
205  mln_precondition(exact(win).is_valid());
206 
207  mln_concrete(I)
208  output = internal::erosion_tolerant_dispatch(input, win, rank);
209 
210  trace::exiting("morpho::erosion_tolerant");
211  return output;
212  }
213 
214 # endif // ! MLN_INCLUDE_ONLY
215 
216  } // end of namespace mln::morpho
217 
218 } // end of namespace mln
219 
220 
221 #endif // ! MLN_MORPHO_EROSION_TOLERANT_HH