$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sauvola_ms_split.hh
1 // Copyright (C) 2010, 2011, 2012, 2013 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 SCRIBO_BINARIZATION_SAUVOLA_MS_SPLIT_HH
28 # define SCRIBO_BINARIZATION_SAUVOLA_MS_SPLIT_HH
29 
30 # include <mln/core/concept/image.hh>
31 
32 # include <mln/border/resize.hh>
33 
34 # include <mln/data/transform.hh>
35 # include <mln/data/split.hh>
36 
37 # include <scribo/binarization/sauvola_ms.hh>
38 
43 
44 namespace scribo
45 {
46 
47  using namespace mln;
48 
49 
50  namespace binarization
51  {
52 
73  template <typename I>
74  mln_ch_value(I, bool)
75  sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
76  unsigned s, unsigned min_ntrue, double k2,
77  double k3, double k4);
78 
84  template <typename I>
85  mln_ch_value(I, bool)
86  sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
87  unsigned s, unsigned min_ntrue, double K);
88 
89 
95  template <typename I>
96  mln_ch_value(I, bool)
97  sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
98  unsigned s, unsigned min_ntrue);
99 
100 
101 
102 # ifndef MLN_INCLUDE_ONLY
103 
104 
105  template <typename I>
106  mln_ch_value(I, bool)
107  sauvola_ms_split(const Image<I>& input_1_, unsigned w_1,
108  unsigned s, unsigned min_ntrue, double k2,
109  double k3, double k4)
110  {
111  mln_trace("scribo::binarization::sauvola_ms_split");
112 
113  mln_precondition(exact(input_1_).is_valid());
114  mlc_is(mln_value(I), value::rgb8)::check();
115 
116  const I& input_1 = exact(input_1_);
117 
118  typedef mln_ch_value(I,bool) bin_t;
119 
120  mln_ch_value(I, value::int_u8) r_i, g_i, b_i;
121 
122  binarization::internal::k2 = k2;
123  binarization::internal::k3 = k3;
124  binarization::internal::k4 = k4;
125 
126  // Split the rgb8 image into 3 intensity images.
127  mln::data::split(input_1, r_i, g_i, b_i);
128 
129  bin_t r_b, g_b, b_b;
130 
131  r_b = sauvola_ms(r_i, w_1, s);
132  g_b = sauvola_ms(g_i, w_1, s);
133  b_b = sauvola_ms(b_i, w_1, s);
134 
135  border::resize(r_b, input_1.border());
136  border::resize(g_b, input_1.border());
137  border::resize(b_b, input_1.border());
138 
139  bin_t output;
140  initialize(output, input_1);
141 
142  typedef bool * b_ptr_t;
143  b_ptr_t
144  out_ptr = output.buffer(),
145  r_ptr = r_b.buffer(),
146  g_ptr = g_b.buffer(),
147  b_ptr = b_b.buffer();
148 
149  unsigned ntrue;
150  for (unsigned n = 0; n < output.nelements(); ++n)
151  {
152  ntrue = 0;
153  if (*r_ptr)
154  ++ntrue;
155  if (*g_ptr)
156  ++ntrue;
157  if (*b_ptr)
158  ++ntrue;
159 
160  *out_ptr++ = ntrue >= min_ntrue;
161 
162  ++r_ptr;
163  ++g_ptr;
164  ++b_ptr;
165  }
166 
167  return output;
168  }
169 
170 
171  template <typename I>
172  mln_ch_value(I, bool)
173  sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
174  unsigned s, unsigned min_ntrue, double K)
175  {
176  return sauvola_ms_split(input_1, w_1, s, min_ntrue,
177  K, K, K);
178  }
179 
180 
181  template <typename I>
182  mln_ch_value(I, bool)
183  sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
184  unsigned s, unsigned min_ntrue)
185  {
186  return sauvola_ms_split(input_1, w_1, s, min_ntrue,
187  SCRIBO_DEFAULT_SAUVOLA_K);
188  }
189 
190 # endif // ! MLN_INCLUDE_ONLY
191 
192  } // end of namespace scribo::binarization
193 
194 } // end of namespace scribo
195 
196 
197 #endif // ! SCRIBO_BINARIZATION_SAUVOLA_MS_SPLIT_HH