$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
from_single_left_link_wrt_h_ratio.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_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH
28 # define SCRIBO_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH
29 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 
38 # include <mln/accu/center.hh>
39 
40 # include <mln/labeling/compute.hh>
41 
42 # include <mln/math/abs.hh>
43 
44 # include <mln/util/array.hh>
45 
46 
47 # include <scribo/core/macros.hh>
48 # include <scribo/core/component_set.hh>
49 # include <scribo/core/object_links.hh>
50 # include <scribo/core/object_groups.hh>
51 
52 # include <scribo/filter/object_links_bbox_h_ratio.hh>
53 # include <scribo/primitive/link/with_single_left_link.hh>
54 
55 # include <scribo/primitive/link/compute.hh>
56 # include <scribo/primitive/group/apply.hh>
57 # include <scribo/primitive/group/from_single_link.hh>
58 
59 
60 namespace scribo
61 {
62 
63  namespace primitive
64  {
65 
66  namespace regroup
67  {
68 
76  //
77  template <typename L>
78  inline
79  object_groups<L>
80  from_single_left_link_wrt_h_ratio(const object_groups<L>& groups,
81  unsigned neighb_max_distance,
82  double hratio);
83 
84 
88  template <typename L>
89  inline
90  object_groups<L>
91  from_single_left_link_wrt_h_ratio(const object_groups<L>& groups);
92 
93 
94 # ifndef MLN_INCLUDE_ONLY
95 
96 
97  // Facades
98 
99  template <typename L>
100  inline
101  object_groups<L>
102  from_single_left_link_wrt_h_ratio(const object_groups<L>& groups,
103  unsigned neighb_max_distance,
104  double hratio)
105  {
106  mln_trace("scribo::primitive::regroup::from_single_left_link_wrt_h_ratio");
107 
108  mln_precondition(groups.is_valid());
109 
110 
111  object_groups<L> output = groups.duplicate();
112 
113  fun::i2v::array<mln_value(L)> relabel_fun;
114  component_set<L>
115  components = primitive::group::apply(groups, relabel_fun);
116 
117  object_links<L>
118  links = primitive::link::with_single_left_link(components,
119  neighb_max_distance);
120 
121  links = filter::object_links_bbox_h_ratio(links, hratio);
122 
123 
124  object_groups<L>
125  new_groups = primitive::group::from_single_link(links);
126 
127  // Preserve the original groups ids but merge newly regrouped
128  // groups.
129  for_all_groups(g, new_groups)
130  if (new_groups(g).card() > 1)
131  for (unsigned i = 1; i < new_groups(g).component_ids().nelements(); ++i)
132  output(relabel_fun(new_groups(g).component_ids()(0)))
133  .merge(output(relabel_fun(new_groups(g).component_ids()(i))));
134 
135  return output;
136  }
137 
138 
139  template <typename L>
140  inline
141  object_groups<L>
142  from_single_left_link_wrt_h_ratio(const object_groups<L>& groups)
143  {
144  return from_single_left_link_wrt_h_ratio(groups,
145  mln_max(unsigned), 1.60f);
146  }
147 
148 
149 # endif // ! MLN_INCLUDE_ONLY
150 
151  } // end of namespace scribo::primitive::regroup
152 
153  } // end of namespace scribo::primitive
154 
155 } // end of namespace scribo
156 
157 #endif // ! SCRIBO_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH