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