$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wolf.hh
1 // Copyright (C) 2012, 2013 EPITA Research and Development Laboratory
2 // (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 SCRIBO_BINARIZATION_WOLF_HH
28 # define SCRIBO_BINARIZATION_WOLF_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <scribo/binarization/internal/wolf_functor.hh>
36 # include <scribo/binarization/internal/local_threshold_core.hh>
37 # include <scribo/binarization/internal/global_max_stddev_functor.hh>
38 # include <scribo/util/integral_sum_sum2_global_min_functor.hh>
39 
40 namespace scribo
41 {
42 
43  namespace binarization
44  {
45 
46  using namespace mln;
47 
48 
63  template <typename I>
64  mln_ch_value(I, bool)
65  wolf(const Image<I>& input, unsigned window_size, double K);
66 
67 
68 
80  template <typename I>
81  mln_ch_value(I, bool)
82  wolf(const Image<I>& input, unsigned window_size);
83 
84 
90  template <typename I>
91  mln_ch_value(I, bool)
92  wolf(const Image<I>& input);
93 
94 
95 # ifndef MLN_INCLUDE_ONLY
96 
97  // Facades
98 
99  template <typename I>
100  mln_ch_value(I, bool)
101  wolf(const Image<I>& input, unsigned window_size, double K)
102  {
103  mln_trace("scribo::binarization::wolf");
104 
105  mln_precondition(exact(input).is_valid());
106 
107  int integral_size_ratio = internal::wolf_functor<I>::step;
108 
109  // Make sure the image sizes are a multiple of 3 in each
110  // dimension. (browsing while binarizing relies on that
111  // property).
113  sub_domains = scribo::util::compute_sub_domains(input, 1, integral_size_ratio);
114 
115  border::adjust(input, sub_domains(1).second());
116  border::mirror(input);
117 
120  integral = scribo::util::init_integral_image(input, integral_size_ratio, fi,
121  sub_domains[2].first(),
122  sub_domains[2].second());
123 
124  window_size /= integral_size_ratio;
125  if (window_size % 2)
126  window_size += 2;
127  else
128  window_size += 1;
129 
130 
131  // Compute max(stddev) of all windows.
132  internal::global_max_stddev<I> f_max_stddev;
133  scribo::canvas::integral_browsing(integral, 1, window_size,
134  window_size, integral_size_ratio, f_max_stddev);
135 
136  // Binarize !
137  internal::wolf_functor<I>
138  f(input, K, fi.global_min(), f_max_stddev.max_stddev);
139  scribo::canvas::integral_browsing(integral, 1, window_size,
140  window_size, integral_size_ratio, f);
141 
142  return f.output;
143  }
144 
145 
146  template <typename I>
147  mln_ch_value(I, bool)
148  wolf(const Image<I>& input, unsigned window_size)
149  {
150  return wolf(input, window_size, SCRIBO_DEFAULT_WOLF_K);
151  }
152 
153 
154  template <typename I>
155  mln_ch_value(I, bool)
156  wolf(const Image<I>& input)
157  {
158  return wolf(input, 11);
159  }
160 
161 
162 # endif // ! MLN_INCLUDE_ONLY
163 
164 
165  } // end of namespace scribo::binarization
166 
167 } // end of namespace scribo
168 
169 
170 #endif // ! SCRIBO_BINARIZATION_WOLF_HH