$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
non_text_hdoc.hh
1 // Copyright (C) 2011 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 
32 
33 #ifndef SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_HDOC_HH
34 # define SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_HDOC_HH
35 
36 # include <mln/morpho/elementary/dilation.hh>
37 
38 # include <mln/draw/box_plain.hh>
39 # include <mln/morpho/closing/structural.hh>
40 # include <mln/win/rectangle2d.hh>
41 
42 # include <scribo/make/text_components_image.hh>
43 # include <scribo/make/text_blocks_image.hh>
44 
45 # include <scribo/primitive/extract/internal/union.hh>
46 # include <scribo/debug/logger.hh>
47 
48 # include <scribo/filter/objects_small.hh>
49 # include <scribo/filter/objects_on_border.hh>
50 # include <scribo/filter/objects_v_thin.hh>
51 # include <scribo/filter/objects_h_thin.hh>
52 
53 //DEBUG
54 #include <mln/util/timer.hh>
55 #include <mln/io/pbm/save.hh>
56 
57 
58 namespace scribo
59 {
60 
61  namespace primitive
62  {
63 
64  namespace extract
65  {
66 
67  using namespace mln;
68 
73  template <typename L>
74  component_set<L>
75  non_text_hdoc(const document<L>& doc, unsigned closing_size);
76 
77 
78 # ifndef MLN_INCLUDE_ONLY
79 
80  namespace internal
81  {
82 
83  } // end of namespace scribo::primitive::extract::internal
84 
85 
86 
87  // FACADE
88 
89  template <typename L>
90  component_set<L>
91  non_text_hdoc(const document<L>& doc, unsigned closing_size)
92  {
93  mln_trace("scribo::primitive::extract::non_text_hdoc");
94 
95  mln_precondition(doc.is_valid());
96  mln_precondition(doc.has_text());
97 
98  mln_ch_value(L,bool)
99  element_image = duplicate(doc.binary_image_wo_seps());
100 
101  // Mask text areas.
102  const paragraph_set<L>& parset = doc.paragraphs();
103  for_all_paragraphs(p, parset)
104  if (parset(p).is_valid())
105  for_all_paragraph_lines(l, parset(p).line_ids())
106  {
107  line_id_t lid = parset(p).line_ids()(l);
108  mln::draw::box_plain(element_image, doc.lines()(lid).bbox(), false);
109  }
110 
111  element_image = morpho::closing::structural(element_image,
112  win::rectangle2d(closing_size,
113  closing_size));
114  // Debug
115  {
116  debug::logger().log_image(debug::AuxiliaryResults,
117  element_image,
118  "non_text_hdoc_element_image");
119  }
120 
121 
122  mln_value(L) ncomps;
123 
124  // FIXME: we should not tag elements as image here since we
125  // just don't know!
126  component_set<L>
127  elements = primitive::extract::components(element_image,
128  c8(), ncomps,
129  component::Image);
130 
131  elements = scribo::filter::components_small(elements, 200);
132  elements = scribo::filter::components_on_border(elements);
133 
134  elements = scribo::filter::objects_v_thin(elements,
135  0.03 * doc.image().domain().height());
136  elements = scribo::filter::objects_h_thin(elements,
137  0.03 * doc.image().domain().width());
138 
139  // Debug
140  {
141  debug::logger().log_image(debug::Results,
142  elements.labeled_image(),
143  "non_text_hdoc_components");
144  }
145 
146  return elements;
147  }
148 
149 # endif // ! MLN_INCLUDE_ONLY
150 
151 
152  } // end of namespace scribo::primitive::extract
153 
154  } // end of namespace scribo::primitive
155 
156 } // end of namespace scribo
157 
158 #endif // ! SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_HDOC_HH