$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
objects_in_borders.hh
1 // Copyright (C) 2013 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 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH
27 # define SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH
28 
33 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/geom/all.hh>
37 # include <scribo/core/component_set.hh>
38 # include <scribo/util/box_is_included.hh>
39 
40 namespace scribo
41 {
42 
43  namespace filter
44  {
45 
46  using namespace mln;
47 
48 
78  template <typename L>
79  void
80  objects_in_borders(component_set<L>& components, float vratio, float hratio);
81 
82 
83 # ifndef MLN_INCLUDE_ONLY
84 
85  template <typename L>
86  void
87  objects_in_borders(component_set<L>& components, float vratio, float hratio)
88  {
89  mln_trace("scribo::filter::objects_in_borders");
90 
91  mln_precondition(components.is_valid());
92 
93  const L& ima = components.labeled_image();
94 
95  unsigned
96  hborder_size = hratio * std::min(ima.domain().width(), ima.domain().height()),
97  vborder_size = vratio * std::min(ima.domain().width(), ima.domain().height());
98 
110  point2d
111  ptl = ima.domain().pmin(),
112  pt(geom::min_row(ima), geom::max_col(ima) - vborder_size),
113  ptr(hborder_size, geom::max_col(ima)),
114  pbr = ima.domain().pmax(),
115  pb(geom::max_row(ima), vborder_size),
116  pbl(geom::max_row(ima) - hborder_size, geom::min_col(ima));
117 
118  box2d
119  bt(ptl, ptr),
120  br(pt, pbr),
121  bb(pbl, pbr),
122  bl(ptl, pb);
123 
124  for_all_comps(c, components)
125  if (components(c).is_valid())
126  if (util::box_is_included(components(c).bbox(), bt)
127  || util::box_is_included(components(c).bbox(), br)
128  || util::box_is_included(components(c).bbox(), bb)
129  || util::box_is_included(components(c).bbox(), bl))
130  {
131  components(c).update_tag(component::Ignored);
132  }
133 
134  }
135 
136 # endif // ! MLN_INCLUDE_ONLY
137 
138  } // end of namespace scribo::filter
139 
140 } // end of namespace scribo
141 
142 #endif // ! SCRIBO_FILTER_OBJECTS_IN_BORDERS_HH