$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
text_in_doc_preprocess.hh
1 // Copyright (C) 2010, 2011, 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_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
28 # define SCRIBO_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
29 
33 
34 
35 #include <mln/core/concept/image.hh>
36 #include <mln/data/transform.hh>
37 #include <mln/fun/v2v/rgb_to_int_u.hh>
38 
39 #include <scribo/binarization/sauvola_ms.hh>
40 
41 #include <scribo/preprocessing/split_bg_fg.hh>
42 #include <scribo/preprocessing/deskew.hh>
43 
44 #include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh>
45 
46 namespace scribo
47 {
48 
49  namespace toolchain
50  {
51 
52  using namespace mln;
53 
71  template <typename I>
72  mln_ch_value(I,bool)
73  text_in_doc_preprocess(const Image<I>& input, bool enable_fg_bg,
74  unsigned lambda, double K, bool enable_deskew,
75  bool verbose);
76 
82  template <typename I>
83  mln_ch_value(I,bool)
84  text_in_doc_preprocess(const Image<I>& input, bool enable_fg_bg,
85  bool verbose);
86 
87 
101  template <typename I>
102  mln_ch_value(I,bool)
103  text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
104  bool verbose);
105 
128  template <typename I>
129  mln_ch_value(I,bool)
130  text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
131  double k2, double k3, double k4, bool enable_fg_bg,
132  Image<I>& fg, bool enable_deskew, bool verbose);
133 
138  template <typename I>
139  mln_ch_value(I,bool)
140  text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
141  bool enable_fg_bg, Image<I>& fg,
142  bool enable_deskew, bool verbose);
143 
144 
145 # ifndef MLN_INCLUDE_ONLY
146 
147 
148  template <typename I>
149  mln_ch_value(I,bool)
150  text_in_doc_preprocess(const Image<I>& input, bool enable_fg_bg,
151  bool verbose)
152  {
153  return text_in_doc_preprocess(input, enable_fg_bg, 0.34, verbose);
154  }
155 
156 
157  template <typename I>
158  mln_ch_value(I,bool)
159  text_in_doc_preprocess(const Image<I>& input_, bool enable_fg_bg,
160  unsigned lambda, double K, bool enable_deskew,
161  bool verbose)
162  {
163  const I& input = exact(input_);
164  mln_precondition(input.is_valid());
165 
166  if (enable_fg_bg && lambda == 0)
167  lambda = 1.2 * (input.nrows() + input.ncols());
168 
169  mln_concrete(I) tmp_fg;
170  mln_ch_value(I,bool)
171  output = text_in_doc_preprocess(input, lambda, K, K, K,
172  enable_fg_bg, tmp_fg, enable_deskew, verbose);
173 
174  return output;
175  }
176 
177  template <typename I>
178  mln_ch_value(I,bool)
179  text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
180  bool verbose)
181  {
182  I tmp;
183  return text_in_doc_preprocess(input, lambda, 0.34, true, tmp, false, verbose);
184  }
185 
186 
187  template <typename I>
188  mln_ch_value(I,bool)
189  text_in_doc_preprocess(const Image<I>& input_, unsigned lambda,
190  double k2, double k3, double k4, bool enable_fg_bg,
191  Image<I>& fg, bool enable_deskew, bool verbose)
192  {
193  mln_trace("scribo::toolchain::text_in_doc_preprocess");
194 
195  const I& input = exact(input_);
196  mln_precondition(input.is_valid());
197 
198  internal::text_in_doc_preprocess_functor<I> f;
199 
200  // Setup functor.
201  f.sauvola_k2 = k2;
202  f.sauvola_k3 = k3;
203  f.sauvola_k4 = k4;
204  f.enable_fg_extraction = enable_fg_bg;
205  f.lambda = lambda;
206  f.enable_deskew = enable_deskew;
207  f.verbose = verbose;
208 
209  // Get results.
210  mln_ch_value(I,bool) output = f(input);
211  exact(fg) = f.fg;
212 
213  return output;
214  }
215 
216 
217  template <typename I>
218  mln_ch_value(I,bool)
219  text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
220  bool enable_fg_bg, Image<I>& fg,
221  bool enable_deskew, bool verbose)
222  {
223  text_in_doc_preprocess(input, lambda, SCRIBO_DEFAULT_SAUVOLA_K,
224  SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_K,
225  enable_fg_bg, fg, enable_deskew, verbose);
226  }
227 
228 # endif // ! MLN_INCLUDE_ONLY
229 
230 
231  } // end of namespace scribo::toolchain
232 
233 } // end of namespace scribo
234 
235 
236 #endif // SCRIBO_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
237