$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
text_areas_image.hh
1 // Copyright (C) 2010, 2011, 2014 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 
28 #ifndef SCRIBO_DEBUG_TEXT_AREAS_IMAGE_HH
29 # define SCRIBO_DEBUG_TEXT_AREAS_IMAGE_HH
30 
34 
35 # include <mln/core/concept/image.hh>
36 
37 # include <mln/core/image/imorph/tr_image.hh>
38 
39 # include <mln/core/routine/duplicate.hh>
40 
41 # include <mln/data/paste.hh>
42 # include <mln/data/fill.hh>
43 
44 # include <mln/fun/x2x/translation.hh>
45 
46 # include <mln/math/max.hh>
47 
48 # include <mln/literal/black.hh>
49 
50 # include <scribo/core/component_set.hh>
51 
52 namespace scribo
53 {
54 
55  namespace debug
56  {
57 
58  using namespace mln;
59 
64  template <typename I, typename L>
65  mln_concrete(I)
66  text_areas_image(const Image<I>& input_rgb,
67  const scribo::component_set<L>& comps);
68 
69 
70 # ifndef MLN_INCLUDE_ONLY
71 
72  template <typename I, typename L>
73  mln_concrete(I)
74  text_areas_image(const Image<I>& input_rgb_,
75  const scribo::component_set<L>& comps)
76  {
77  mln_trace("scribo::debug::text_areas_image");
78 
79  const I& input_rgb = exact(input_rgb_);
80  mln_precondition(input_rgb.is_valid());
81 
82  typedef mln_site(I) P;
83 
84  unsigned shift = 5;
85  float height = 1, width = 0;
86  for_all_comps(i, comps)
87  if (comps(i).is_valid())
88  {
89  height += comps(i).bbox().nrows() + shift;
90  width = math::max(static_cast<float>(comps(i).bbox().ncols()),
91  width);
92  }
93  if (width == 0)
94  width = 1;
95 
96  I output(height, width);
97  data::fill(output, literal::black);
98 
99  algebra::vec<2, float> dv;
100  dv[0] = 0;
101  dv[1] = 0;
102  for_all_comps(i, comps)
103  if (comps(i).is_valid())
104  {
105  typedef mln::sub_image<I, box2d> tmp_t;
106  tmp_t tmp = duplicate(input_rgb | comps(i).bbox());
107 
109  trans_t trans(dv - comps(i).bbox().pmin().to_vec());
110 
111  mln_domain(I)
112  tr_box(comps(i).bbox().pmin().to_vec() + trans.t(),
113  comps(i).bbox().pmax().to_vec() + trans.t());
114 
115  typedef mln_domain(I) domain_t;
116  tr_image<domain_t, tmp_t, trans_t> tr_ima(tr_box, tmp, trans);
117 
118  data::paste(tr_ima, output);
119  dv[0] += comps(i).bbox().nrows() + shift;
120  }
121 
122  return output;
123  }
124 
125 
126 # endif // ! MLN_INCLUDE_ONLY
127 
128 
129  } // end of namespace scribo::debug
130 
131 } // end of namespace scribo
132 
133 
134 #endif // ! SCRIBO_DEBUG_TEXT_AREAS_IMAGE_HH