$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mean_and_base_lines_image.hh
1 // Copyright (C) 2010, 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 
27 #ifndef SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH
28 # define SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH
29 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/data/convert.hh>
37 # include <mln/value/rgb8.hh>
38 # include <mln/literal/colors.hh>
39 
40 # include <mln/draw/box.hh>
41 # include <mln/draw/line.hh>
42 # include <mln/draw/dashed_line.hh>
43 
44 # include <scribo/core/line_set.hh>
45 
46 
47 namespace scribo
48 {
49 
50  namespace debug
51  {
52 
53  using namespace mln;
54 
55 
71  //
72  template <typename I, typename L>
73  mln_ch_value(I,value::rgb8)
74  mean_and_base_lines_image(const Image<I>& input,
75  const line_set<L>& lines,
76  const value::rgb8& bbox_value,
77  const value::rgb8& meanline_value,
78  const value::rgb8& baseline_value);
79 
85  //
86  template <typename I, typename L>
87  mln_ch_value(I,value::rgb8)
88  mean_and_base_lines_image(const Image<I>& input,
89  const line_set<L>& lines);
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94 
95  template <typename I, typename L>
96  mln_ch_value(I,value::rgb8)
97  mean_and_base_lines_image(const Image<I>& input,
98  const line_set<L>& lines,
99  const value::rgb8& bbox_value,
100  const value::rgb8& meanline_value,
101  const value::rgb8& baseline_value)
102  {
103  mln_trace("scribo::debug::mean_and_base_lines_image");
104  mln_precondition(exact(input).is_valid());
105 
106  mln_ch_value(I, value::rgb8)
107  output = data::convert(value::rgb8(), input);
108 
109  for_all_lines(l, lines)
110  {
111  if (! lines(l).is_hidden())
112  {
113  mln::draw::box(output, lines(l).bbox(), bbox_value);
114 
115  if (! (lines(l).type() == line::Text
116  || (lines(l).type() == line::Undefined
117  && lines(l).tag() == line::None
118  && lines(l).card() > 2)))
119  continue;
120 
121  point2d
122  b_top(lines(l).meanline(), lines(l).bbox().pmin().col()),
123  e_top(lines(l).meanline(), lines(l).bbox().pmax().col()),
124  b_bot(lines(l).baseline(), lines(l).bbox().pmin().col()),
125  e_bot(lines(l).baseline(), lines(l).bbox().pmax().col());
126 
127  mln::draw::line(output, b_bot, e_bot, baseline_value);
128  mln::draw::dashed_line(output, b_top, e_top, meanline_value);
129 
130  }
131  }
132 
133  return output;
134  }
135 
136 
137  template <typename I, typename L>
138  mln_ch_value(I,value::rgb8)
139  mean_and_base_lines_image(const Image<I>& input,
140  const line_set<L>& lines)
141  {
142  return mean_and_base_lines_image(input, lines,
143  literal::purple, literal::blue,
144  literal::cyan);
145  }
146 
147 # endif // ! MLN_INCLUDE_ONLY
148 
149  } // end of namespace scribo::debug
150 
151 } // end of namespace scribo
152 
153 
154 #endif // ! SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH