$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
components_features.hh
1 // Copyright (C) 2011, 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_ESTIM_COMPONENT_FEATURES_HH
27 # define SCRIBO_ESTIM_COMPONENT_FEATURES_HH
28 
29 # include <mln/core/image/image2d.hh>
30 # include <mln/core/alias/neighb2d.hh>
31 # include <mln/topo/skeleton/crest.hh>
32 # include <mln/topo/skeleton/is_simple_point.hh>
33 # include <mln/transform/distance_front.hh>
34 # include <mln/logical/not.hh>
35 # include <mln/make/w_window2d_int.hh>
36 # include <mln/value/int_u8.hh>
37 # include <mln/arith/revert.hh>
38 # include <mln/morpho/skeleton_constrained.hh>
39 # include <mln/core/routine/extend.hh>
40 # include <mln/labeling/blobs.hh>
41 # include <mln/accu/stat/mean.hh>
42 # include <mln/make/dual_neighb.hh>
43 
44 
45 # include <mln/data/compute.hh>
46 # include <mln/io/pbm/save.hh>
47 # include <mln/io/pgm/save.hh>
48 # include <mln/util/timer.hh>
49 
50 # include <scribo/core/component_set.hh>
51 # include <scribo/estim/font_color.hh>
52 # include <scribo/estim/font_boldness.hh>
53 
54 #include <mln/data/convert.hh>
55 
56 
57 namespace scribo
58 {
59 
60  namespace estim
61  {
62 
63  using namespace mln;
64 
68  //
69  template <typename I, typename J, typename L>
70  component_set<L>
71  components_features(const Image<I>& input, const Image<J>& bin_input,
72  const component_set<L>& components);
73 
74 
75 # ifndef MLN_INCLUDE_ONLY
76 
77 
78  template <typename I, typename J, typename L>
79  component_set<L>
80  components_features(const Image<I>& input_, const Image<J>& bin_input_,
81  const component_set<L>& components)
82  {
83  mln_trace("scribo::estim::components_features");
84 
85  const I& input = exact(input_);
86  const J& bin_input = exact(bin_input_);
87 
88  mln_precondition(input.is_valid());
89  mln_precondition(bin_input.is_valid());
90 
91  component_set<L> output = components.duplicate();
92 
93  component_features_data features;
94  features.valid = true;
95 
96  typedef mln_concrete(J) B;
97  B skel;
98  L skel_lbl;
99  mln_value(L) nlabels;
100 
101  {
102  int psi = 7;
103  int vals[] = { 0, 9, 0, 9, 0,
104  9, 6, 4, 6, 9,
105  0, 4, 0, 4, 0,
106  9, 6, 4, 6, 9,
107  0, 9, 0, 9, 0 };
108 
109  typedef mln_ch_value(I,value::int_u8) dist_t;
110  dist_t
111  dist = transform::distance_front(logical::not_(bin_input), c8(),
112  mln::make::w_window2d_int(vals),
113  mln_max(value::int_u8));
114  dist_t dist_map = arith::revert(dist);
115  B K = topo::skeleton::crest(bin_input, dist, c8(), psi);
116 
117  typedef
118  neighb<win::multiple_size<2u, window2d, pw::value_<J> > >
119  nbh_t;
120  nbh_t nbh = mln::make::dual_neighb(bin_input, c8(), c4());
121 
122  skel =
123  morpho::skeleton_constrained(bin_input, nbh,
124  topo::skeleton::is_simple_point<nbh_t>(nbh),
125  K, dist_map);
126 
127  }
128 
129  const L& lbl = output.labeled_image();
130 
131  for_all_comps(c, output)
132  {
133  // Estimate component color
134  features.color = data::compute(accu::meta::stat::mean(),
135  ((input | output(c).bbox())
136  | (pw::value(lbl) == pw::cst(c)
137  && pw::value(skel))));
138 
139 
140  // Estimate component boldness
141  features.boldness = internal::boldness_from_lbl(
142  (lbl | output(c).bbox()) | (pw::value(lbl) == pw::cst(c)),
143  (skel | output(c).bbox()) | (pw::value(lbl) == pw::cst(c)));
144 
145  output(c).update_features(features);
146  }
147 
148  return output;
149  }
150 
151 
152 # endif // ! MLN_INCLUDE_ONLY
153 
154  } // end of namespace scribo::estim
155 
156 } // end of namespace scribo
157 
158 # endif // ! SCRIBO_ESTIM_COMPONENT_FEATURES_HH