$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_groups_bboxes_filtered.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 #include <scribo/filter/objects_v_thick.hh>
35 #include <scribo/filter/objects_small.hh>
36 
37 int main(int argc, char *argv[])
38 {
39  using namespace mln;
40  using namespace scribo;
41  using namespace scribo::primitive;
42 
43  if (argc != 3 && argc != 4 && argc != 5 && argc != 6)
44  {
45  std::cerr << "Usage : " << argv[0] << " input.pbm out.pbm [hratio = 2.5] [min_comp_area = 3] [max_comp_height = 300]" << std::endl;
46  std::cerr << "Remove small and large components. Group components and makes sure "
47  << " size ratio is correct." << std::endl;
48  return 1;
49  }
50 
51  typedef mln::value::int_u<30> V;
52  typedef image2d<V> L;
53 
54  image2d<bool> input;
55  io::pbm::load(input, argv[1]);
56 
57  V ncomponents;
60  ncomponents);
61 
62  int
63  min_comp_area = 3,
64  max_comp_height = 300;
65 
66  if (argc >= 5)
67  min_comp_area = atoi(argv[4]);
68  if (argc >= 6)
69  max_comp_height = atoi(argv[5]);
70 
73 
74 
76  left_link = primitive::link::with_single_left_link_dmax_ratio(
77  components,
78 // primitive::link::internal::dmax_width_and_height(1),
80  anchor::MassCenter);
81 
83  right_link = primitive::link::with_single_right_link_dmax_ratio(
84  components,
85 // primitive::link::internal::dmax_width_and_height(1),
87  anchor::MassCenter);
88 
89  // Validating left and right links.
91  merged_links = primitive::link::merge_double_link(left_link,
92  right_link);
93 
94  float hratio = 2.5f;
95  if (argc == 4)
96  hratio = atof(argv[3]);
97 
98 
99  object_links<L> hratio_filtered_links
100  = filter::object_links_bbox_h_ratio(merged_links, hratio);
101 
102 
104  groups = group::from_single_link(hratio_filtered_links);
105 
106  line_set<L> lines(groups);
107 
108  {
109  image2d<bool> output;
110  initialize(output, input);
111  data::fill(output, false);
112 
113  for_all_lines(l, lines)
114  if (lines(l).is_valid())
115  mln::draw::box(output, lines(l).bbox(), true);
116 
117  io::pbm::save(output, argv[2]);
118  }
119 }