$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clean_inplace.hh
1 // Copyright (C) 2010, 2011, 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_TEXT_CLEAN_INPLACE_HH
28 # define SCRIBO_TEXT_CLEAN_INPLACE_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/weighted_window.hh>
36 # include <mln/core/routine/extend.hh>
37 
38 # include <mln/morpho/skeleton_constrained.hh>
39 # include <mln/morpho/dilation.hh>
40 
41 # include <mln/topo/skeleton/is_simple_point.hh>
42 # include <mln/topo/skeleton/crest.hh>
43 
44 # include <mln/logical/not.hh>
45 
46 # include <mln/debug/filename.hh>
47 # include <mln/io/pbm/save.hh>
48 
49 #include <mln/labeling/wrap.hh>
50 #include <mln/win/octagon2d.hh>
51 
52 #include <mln/arith/revert.hh>
53 
54 #include <mln/transform/distance_front.hh>
55 
56 
57 #include <mln/linear/gaussian.hh>
58 #include <mln/value/int_u8.hh>
59 
60 #include <mln/data/convert.hh>
61 #include <mln/value/rgb8.hh>
62 #include <mln/io/pgm/all.hh>
63 
64 #include <scribo/core/line_info.hh>
65 #include <scribo/upsampling/bs2x.hh>
66 #include <scribo/upsampling/eagle.hh>
67 #include <scribo/subsampling/bilinear.hh>
68 
69 
70 namespace scribo
71 {
72 
73  namespace text
74  {
75 
76  using namespace mln;
77 
78 
85  //
86  template <typename L, typename I>
87  void
88  clean_inplace(const line_info<L>& line, Image<I>& input);
89 
90 
91 # ifndef MLN_INCLUDE_ONLY
92 
93  template <typename L, typename I>
94  void
95  clean_inplace(const line_info<L>& line, Image<I>& input_)
96  {
97  mln_trace("scribo::text::clean_inplace");
98 
99  I& input = exact(input_);
100  mlc_bool(mln_site_(I)::dim == 2)::check();
101  mlc_equal(mln_value(I),bool)::check();
102  mln_precondition(input.is_valid());
103  mln_precondition(line.is_valid());
104 
105 
106  if (line.x_height() < 5) // Non significative text/remaining lines...
107  return;
108 
109  float fact = line.x_height() / 40.0f;
110  if (fact < 1)
111  {
112  while (fact < 0.90)
113  {
114  input = scribo::upsampling::eagle(input); // 2x upsampling
115  fact *= 2.0f;
116  }
117  }
118  else if (fact > 2.5f)
119  {
120  input = subsampling::bilinear(input, int(std::ceil(fact - 0.5))); // math::floor instead?
121  }
122 
123  }
124 
125 # endif // ! MLN_INCLUDE_ONLY
126 
127  } // end of namespace scribo::text
128 
129 } // end of namespace scribo
130 
131 #endif // ! SCRIBO_TEXT_CLEAN_INPLACE_HH