$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Scribo
Modules
Namespaces
Classes
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
denoise_fg.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_FG_HH
28
# define SCRIBO_PREPROCESSING_DENOISE_FG_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
38
# include <mln/accu/math/count.hh>
39
40
# include <mln/core/alias/neighb2d.hh>
41
42
# include <mln/util/array.hh>
43
# include <mln/fun/i2v/array.hh>
44
45
# include <mln/data/transform.hh>
46
47
# include <mln/labeling/compute.hh>
48
# include <mln/labeling/foreground.hh>
49
50
# include <scribo/fun/v2b/label_to_bool.hh>
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_fg
(const
Image
<I>& input, const
Neighborhood
<N>& nbh,
75
unsigned
min_card);
76
77
78
# ifndef MLN_INCLUDE_ONLY
79
80
81
template
<
typename
I,
typename
N>
82
mln_concrete
(I)
83
denoise_fg
(const
Image
<I>& input_, const
Neighborhood
<N>& nbh_,
84
unsigned
min_card)
85
{
86
mln_trace(
"scribo::preprocessing::denoise_fg"
);
87
88
const
I& input =
exact
(input_);
89
const
N& nbh =
exact
(nbh_);
90
mlc_equal(mln_value(I),
bool
)::check();
91
mln_precondition(input.is_valid());
92
93
unsigned
nlabels;
94
image2d<unsigned>
lbl =
labeling::foreground
(input, nbh, nlabels);
95
96
mln::util::array<unsigned>
97
result =
labeling::compute
(
accu::meta::math::count
(), lbl, nlabels);
98
99
mln::fun::i2v::array<bool>
f(nlabels + 1,
true
);
100
f(0) =
false
;
101
for
(
unsigned
i = 1; i <= nlabels; ++i)
102
if
(result(i) < min_card)
103
f(i) =
false
;
104
105
scribo::fun::v2b::label_to_bool<unsigned>
relabel_f(f);
106
mln_concrete
(I)
107
output =
data
::
transform
(lbl, relabel_f);
108
109
return output;
110
}
111
112
# endif // ! MLN_INCLUDE_ONLY
113
114
}
// end of namespace scribo::preprocessing
115
116
}
// end of namespace scribo
117
118
# endif // SCRIBO_PREPROCESSING_DENOISE_FG_HH
scribo
scribo
preprocessing
denoise_fg.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)