$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wolf_fast.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_FAST_HH
28 # define SCRIBO_BINARIZATION_WOLF_FAST_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <scribo/binarization/internal/wolf_functor_fast.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 
67  template <typename I>
68  mln_ch_value(I, bool)
69  wolf_fast(const Image<I>& input, unsigned window_size, double K);
70 
71 
72 
79  template <typename I>
80  mln_ch_value(I, bool)
81  wolf_fast(const Image<I>& input, unsigned window_size);
82 
83 
89  template <typename I>
90  mln_ch_value(I, bool)
91  wolf_fast(const Image<I>& input);
92 
93 
94 # ifndef MLN_INCLUDE_ONLY
95 
96  // Facades
97 
98  template <typename I>
99  mln_ch_value(I, bool)
100  wolf_fast(const Image<I>& input, unsigned window_size, double K)
101  {
102  mln_trace("scribo::binarization::wolf_fast");
103 
104  mln_precondition(exact(input).is_valid());
105 
106 
107  // Make sure the image sizes are a multiple of 3 in each
108  // dimension. (browsing while binarizing relies on that
109  // property).
111  sub_domains = scribo::util::compute_sub_domains(input, 1, 3);
112 
113  border::adjust(input, sub_domains(1).second());
114  border::mirror(input);
115 
118  integral = scribo::util::init_integral_image(input, 3, fi,
119  sub_domains[2].first(),
120  sub_domains[2].second());
121 
122  window_size /= 3;
123  if (window_size % 2)
124  window_size += 2;
125  else
126  window_size += 1;
127 
128 
129  // Compute max(stddev) of all windows.
130  internal::global_max_stddev<I> f_max_stddev;
131  scribo::canvas::integral_browsing(integral, 1, window_size,
132  window_size, 3, f_max_stddev);
133 
134  // Binarize !
135  internal::wolf_functor_fast<I>
136  f(input, K, fi.global_min(), f_max_stddev.max_stddev);
137  scribo::canvas::integral_browsing(integral, 1, window_size,
138  window_size, 3, f);
139 
140  return f.output;
141  }
142 
143 
144  template <typename I>
145  mln_ch_value(I, bool)
146  wolf_fast(const Image<I>& input, unsigned window_size)
147  {
148  return wolf_fast(input, window_size, SCRIBO_DEFAULT_WOLF_K);
149  }
150 
151 
152  template <typename I>
153  mln_ch_value(I, bool)
154  wolf_fast(const Image<I>& input)
155  {
156  return wolf_fast(input, 11);
157  }
158 
159 
160 # endif // ! MLN_INCLUDE_ONLY
161 
162 
163  } // end of namespace scribo::binarization
164 
165 } // end of namespace scribo
166 
167 
168 #endif // ! SCRIBO_BINARIZATION_WOLF_FAST_HH