Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
log.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_LOG_HH
27 # define MLN_LINEAR_LOG_HH
28 
32 
33 # include <mln/linear/convolve.hh>
34 # include <mln/make/w_window2d.hh>
35 
36 
37 
38 namespace mln
39 {
40 
41  namespace linear
42  {
43 
44  template <typename I>
45  mln_ch_convolve(I, int)
46  LoG_5x5(const Image<I>& input);
47 
48  template <typename I>
49  mln_ch_convolve(I, int)
50  LoG_7x7(const Image<I>& input);
51 
52  template <typename I>
53  mln_ch_convolve(I, int)
54  LoG_13x13(const Image<I>& input);
55 
56  template <typename I>
57  mln_ch_convolve(I, int)
58  LoG_17x17(const Image<I>& input);
59 
60 
61 # ifndef MLN_INCLUDE_ONLY
62 
63  // LoG_5x5 (Cf. Sonka et al., pages 85-86)
64  // This is also a "mexican hat".
65 
66  template <typename I>
67  inline
68  mln_ch_convolve(I, int)
69  LoG_5x5(const Image<I>& input)
70  {
71  trace::entering("linear::LoG_5x5");
72  mln_precondition(exact(input).is_valid());
73  int ws[] = { +0, 0, -1, 0, 0,
74  +0, -1, -2, -1, 0,
75  -1, -2, 16, -2, -1,
76  +0, -1, -2, -1, 0,
77  +0, 0, -1, 0, 0 };
78  mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
79  trace::exiting("linear::LoG_5x5");
80  return output;
81  }
82 
83  // LoG 7x7 (Cf. Russ, p. 250)
84 
85  template <typename I>
86  inline
87  mln_ch_convolve(I, int)
88  LoG_7x7(const Image<I>& input)
89  {
90  trace::entering("linear::LoG_7x7");
91  mln_precondition(exact(input).is_valid());
92  int ws[] = { +0, 0, -1, -1, -1, 0, 0,
93  +0, -1, -3, -3, -3, -1, 0,
94  -1, -3, 0, 7, 0, -3, -1,
95  -1, -3, 7, 24, 7, -3, -1,
96  -1, -3, 0, 7, 0, -3, -1,
97  +0, -1, -3, -3, -3, -1, 0,
98  +0, 0, -1, -1, -1, 0, 0 };
99  mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
100  trace::exiting("linear::LoG_7x7");
101  return output;
102  }
103 
104  // LoG 13x13 (Cf. Russ, p. 250)
105 
106  template <typename I>
107  inline
108  mln_ch_convolve(I, int)
109  LoG_13x13(const Image<I>& input)
110  {
111  trace::entering("linear::LoG_13x13");
112  mln_precondition(exact(input).is_valid());
113  int ws[] = { +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
114  +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
115  +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
116  +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
117  +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
118  -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
119  -1, -2, -4, -2, 6, 19, 24, 19, 6, -2, -4, -2, -1,
120  -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
121  +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
122  +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
123  +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
124  +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
125  +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0 };
126  mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
127  return output;
128  }
129 
130 
131  // LoG 17x17 (Cf. Sonka et al., pages 85-86)
132 
133  template <typename I>
134  inline
135  mln_ch_convolve(I, int)
136  LoG_17x17(const Image<I>& input)
137  {
138  trace::entering("linear::LoG_17x17");
139  mln_precondition(exact(input).is_valid());
140  int ws[] = { +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0,
141  +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
142  +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
143  +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
144  +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
145  +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
146  -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
147  -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
148  -1,-1,-3,-3,-3, 4,12,21,24,21,12, 4,-3,-3,-3,-1,-1,
149  -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
150  -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
151  +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
152  +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
153  +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
154  +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
155  +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
156  +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0 };
157  mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
158  trace::exiting("linear::LoG_17x17");
159  return output;
160  }
161 
162 # endif // ! MLN_INCLUDE_ONLY
163 
164  } // end of namespace mln::linear
165 
166 } // end of namespace mln
167 
168 
169 #endif // ! MLN_LINEAR_LOG_HH