$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_groups_bboxes.cc
1 // Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 
17 #include <mln/core/image/image2d.hh>
18 #include <mln/core/alias/neighb2d.hh>
19 #include <mln/io/pbm/all.hh>
20 #include <mln/value/int_u.hh>
21 #include <mln/literal/colors.hh>
22 #include <mln/draw/box.hh>
23 
24 #include <scribo/core/component_set.hh>
25 #include <scribo/core/line_set.hh>
26 #include <scribo/primitive/extract/components.hh>
27 #include <scribo/primitive/group/from_single_link.hh>
28 #include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
29 #include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
30 #include <scribo/primitive/link/merge_double_link.hh>
31 #include <scribo/primitive/link/internal/dmax_width_and_height.hh>
32 
33 #include <scribo/filter/object_links_bbox_h_ratio.hh>
34 
35 int main(int argc, char *argv[])
36 {
37  using namespace mln;
38  using namespace scribo;
39  using namespace scribo::primitive;
40 
41  if (argc != 3 && argc != 4)
42  {
43  std::cerr << "Usage : " << argv[0] << " input.pbm out.pbm [hratio = 2.5]" << std::endl;
44  std::cerr << "Group components and makes sure size ratio is correct." << std::endl;
45  return 1;
46  }
47 
48  typedef mln::value::int_u<30> V;
49  typedef image2d<V> L;
50 
51  image2d<bool> input;
52  io::pbm::load(input, argv[1]);
53 
54  V ncomponents;
57  ncomponents);
58 
59 
61  left_link = primitive::link::with_single_left_link_dmax_ratio(
62  components,
63 // primitive::link::internal::dmax_width_and_height(1),
65  anchor::MassCenter);
66 
68  right_link = primitive::link::with_single_right_link_dmax_ratio(
69  components,
70 // primitive::link::internal::dmax_width_and_height(1),
72  anchor::MassCenter);
73 
74  // Validating left and right links.
76  merged_links = primitive::link::merge_double_link(left_link,
77  right_link);
78 
79  float hratio = 2.5f;
80  if (argc == 4)
81  hratio = atof(argv[3]);
82 
83  object_links<L> hratio_filtered_links
84  = filter::object_links_bbox_h_ratio(merged_links, hratio);
85 
86 
88  groups = group::from_single_link(hratio_filtered_links);
89 
90  line_set<L> lines(groups);
91 
92  image2d<bool> output;
93  initialize(output, input);
94  data::fill(output, false);
95 
96  for_all_lines(l, lines)
97  if (lines(l).is_valid())
98  mln::draw::box(output, lines(l).bbox(), true);
99 
100  io::pbm::save(output, argv[2]);
101 }