$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
denoise_bg.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_PREPROCESSING_DENOISE_BG_HH
28 # define SCRIBO_PREPROCESSING_DENOISE_BG_HH
29 
33 
34 # include <mln/core/image/image2d.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/core/concept/function.hh>
37 # include <mln/data/transform.hh>
38 
39 # include <mln/accu/math/count.hh>
40 
41 # include <mln/core/alias/neighb2d.hh>
42 
43 # include <mln/util/array.hh>
44 # include <mln/fun/i2v/array.hh>
45 
46 # include <mln/labeling/compute.hh>
47 # include <mln/labeling/background.hh>
48 
49 # include <scribo/fun/v2b/label_to_bool.hh>
50 
51 
52 namespace scribo
53 {
54 
55  namespace preprocessing
56  {
57 
58  using namespace mln;
59 
71  //
72  template <typename I, typename N>
73  mln_concrete(I)
74  denoise_bg(const Image<I>& input, const Neighborhood<N>& nbh,
75  unsigned min_card);
76 
77 
78  } // end of namespace scribo::preprocessing
79 
80 } // end of namespace mln
81 
82 
83 # ifndef MLN_INCLUDE_ONLY
84 
85 namespace mln
86 {
87 
88 
89  template <typename L>
90  struct label_to_bool : Function_v2b<label_to_bool<L> >
91  {
92  typedef bool result;
93 
94  label_to_bool(const fun::i2v::array<bool>& f)
95  : f_(f)
96  {}
97 
98  bool operator()(const L& v) const
99  {
100  return f_(v);
101  }
102 
104  };
105 
106 
107 } // end of namespace mln
108 
109 
110 
111 namespace scribo
112 {
113 
114  namespace preprocessing
115  {
116 
117  using namespace mln;
118 
119 
120  template <typename I, typename N>
121  mln_concrete(I)
122  denoise_bg(const Image<I>& input_, const Neighborhood<N>& nbh_,
123  unsigned min_card)
124  {
125  mln_trace("scribo::preprocessing::denoise_bg");
126 
127  const I& input = exact(input_);
128  const N& nbh = exact(nbh_);
129  mlc_equal(mln_value(I), bool)::check();
130  mln_precondition(input.is_valid());
131 
132  unsigned nlabels;
133  image2d<unsigned> lbl = labeling::background(input, nbh, nlabels);
134 
136  result = labeling::compute(accu::meta::math::count(), lbl, nlabels);
137 
138  mln::fun::i2v::array<bool> f(nlabels + 1, false);
139  f(0) = true;
140  for (unsigned i = 1; i <= nlabels; ++i)
141  if (result(i) < min_card)
142  f(i) = true;
143 
145  mln_concrete(I)
146  output = data::transform(lbl, relabel_f);
147 
148  return output;
149  }
150 
151 
152  } // end of namespace scribo::preprocessing
153 
154 } // end of namespace mln
155 
156 
157 # endif // ! MLN_INCLUDE_ONLY
158 
159 # endif // SCRIBO_PREPROCESSING_DENOISE_BG_HH