$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sobel_2d.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_LINEAR_SOBEL_2D_HH
28 # define MLN_LINEAR_SOBEL_2D_HH
29 
35 
36 # include <mln/trait/ch_value.hh>
37 # include <mln/trait/value/nature.hh>
38 
39 # include <mln/metal/int.hh>
40 
41 # include <mln/arith/plus.hh>
42 # include <mln/data/abs.hh>
43 # include <mln/fun/x2v/l1_norm.hh>
44 # include <mln/fun/vv2v/vec.hh>
45 # include <mln/linear/convolve_2x1d.hh>
46 
47 
48 
49 namespace mln
50 {
51 
52  namespace linear
53  {
54 
58 
59 
60  template <typename I>
61  mln_ch_convolve(I, int)
62  sobel_2d_h(const Image<I>& input);
63 
65  template <typename I>
66  mln_ch_convolve(I, int)
67  sobel_2d_v(const Image<I>& input);
68 
70  template <typename I>
71  mln_ch_convolve_grad(I, int)
72  sobel_2d(const Image<I>& input);
73 
75  template <typename I>
76  mln_ch_convolve(I, int)
77  sobel_2d_l1_norm(const Image<I>& input);
79 
80 
81 # ifndef MLN_INCLUDE_ONLY
82 
83 
84  // Facades.
85 
86  template <typename I>
87  inline
88  mln_ch_convolve(I, int)
89  sobel_2d_h(const Image<I>& input)
90  {
91  mln_trace("linear::sobel_2d_h");
92  mln_precondition(exact(input).is_valid());
93 
94  int wh[] = { -1, 0, 1 };
95  int wv[] = { 1,
96  2,
97  1 };
98  mln_ch_convolve(I, int) output = convolve_2x1d(input, wh, wv);
99 
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  mln_trace("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  return output;
119  }
120 
121 
122  template <typename I>
123  mln_ch_convolve_grad(I, int)
124  sobel_2d(const Image<I>& input)
125  {
126  mln_trace("linear::sobel_2d");
127  mln_precondition(exact(input).is_valid());
128 
129  typedef mln_ch_convolve(I, int) J;
130  J h = sobel_2d_h(input),
131  v = sobel_2d_v(input);
132  fun::vv2v::vec<mln_value(J)> f;
133  mln_ch_convolve_grad(I, int) output = data::transform(h, v, f);
134 
135  return output;
136  }
137 
138 
139  template <typename I>
140  mln_ch_convolve(I, int)
141  sobel_2d_l1_norm(const Image<I>& input)
142  {
143  mln_trace("linear::sobel_2d_norm_l1");
144  mln_precondition(exact(input).is_valid());
145 
146  typedef mln_ch_convolve_grad(I, int) G;
147  G grad = sobel_2d(input);
148  fun::x2v::l1_norm<mln_value(G)> f;
149  mln_ch_convolve(I, int) output = data::transform(grad, f);
150 
151  return output;
152  }
153 
154 # endif // ! MLN_INCLUDE_ONLY
155 
156  } // end of namespace mln::linear
157 
158 } // end of namespace mln
159 
160 
161 #endif // ! MLN_LINEAR_SOBEL_2D_HH