Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
sobel_2d.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_LINEAR_SOBEL_2D_HH
27 # define MLN_LINEAR_SOBEL_2D_HH
28 
34 
35 # include <mln/trait/ch_value.hh>
36 # include <mln/trait/value/nature.hh>
37 
38 # include <mln/metal/int.hh>
39 
40 # include <mln/arith/plus.hh>
41 # include <mln/data/abs.hh>
42 # include <mln/fun/x2v/l1_norm.hh>
43 # include <mln/fun/vv2v/vec.hh>
44 # include <mln/linear/convolve_2x1d.hh>
45 
46 
47 
48 namespace mln
49 {
50 
51  namespace linear
52  {
53 
57  template <typename I>
58  mln_ch_convolve(I, int)
59  sobel_2d_h(const Image<I>& input);
60 
62  template <typename I>
63  mln_ch_convolve(I, int)
64  sobel_2d_v(const Image<I>& input);
66 
68  template <typename I>
69  mln_ch_convolve_grad(I, int)
70  sobel_2d(const Image<I>& input);
72 
74  template <typename I>
75  mln_ch_convolve(I, int)
76  sobel_2d_l1_norm(const Image<I>& input);
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82 
83  // Facades.
84 
85  template <typename I>
86  inline
87  mln_ch_convolve(I, int)
88  sobel_2d_h(const Image<I>& input)
89  {
90  trace::entering("linear::sobel_2d_h");
91  mln_precondition(exact(input).is_valid());
92 
93  int wh[] = { -1, 0, 1 };
94  int wv[] = { 1,
95  2,
96  1 };
97  mln_ch_convolve(I, int) output = convolve_2x1d(input, wh, wv);
98 
99  trace::exiting("linear::sobel_2d_h");
100  return output;
101  }
102 
103 
104  template <typename I>
105  inline
106  mln_ch_convolve(I, int)
107  sobel_2d_v(const Image<I>& input)
108  {
109  trace::entering("linear::sobel_2d_v");
110  mln_precondition(exact(input).is_valid());
111 
112  int wh[] = { 1, 2, 1 };
113  int wv[] = { -1,
114  0,
115  +1 };
116  mln_ch_convolve(I, int) output = convolve_2x1d(input, wh, wv);
117 
118  trace::exiting("linear::sobel_2d_v");
119  return output;
120  }
121 
122 
123  template <typename I>
125  sobel_2d(const Image<I>& input)
126  {
127  trace::entering("linear::sobel_2d");
128  mln_precondition(exact(input).is_valid());
129 
130  typedef mln_ch_convolve(I, int) J;
131  J h = sobel_2d_h(input),
132  v = sobel_2d_v(input);
134  mln_ch_convolve_grad(I, int) output = data::transform(h, v, f);
135 
136  trace::exiting("linear::sobel_2d");
137  return output;
138  }
139 
140 
141  template <typename I>
142  mln_ch_convolve(I, int)
143  sobel_2d_l1_norm(const Image<I>& input)
144  {
145  trace::entering("linear::sobel_2d_norm_l1");
146  mln_precondition(exact(input).is_valid());
147 
148  typedef mln_ch_convolve_grad(I, int) G;
149  G grad = sobel_2d(input);
150  fun::x2v::l1_norm<mln_value(G)> f;
151  mln_ch_convolve(I, int) output = data::transform(grad, f);
152 
153  trace::exiting("linear::sobel_2d");
154  return output;
155  }
156 
157 # endif // ! MLN_INCLUDE_ONLY
158 
159  } // end of namespace mln::linear
160 
161 } // end of namespace mln
162 
163 
164 #endif // ! MLN_LINEAR_SOBEL_2D_HH