Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
first_routine.cc
1 
2 
3 
4 // \{
5 #include <mln/core/image/image2d.hh>
6 #include <mln/core/image/dmorph/image_if.hh>
7 #include <mln/core/alias/neighb2d.hh>
8 
9 #include <mln/data/fill.hh>
10 
11 #include <mln/labeling/blobs.hh>
12 #include <mln/labeling/compute.hh>
13 #include <mln/labeling/blobs.hh>
14 
15 #include <mln/data/compare.hh>
16 
17 #include <mln/util/array.hh>
18 
19 #include <mln/value/label_8.hh>
20 
21 #include <mln/accu/math/count.hh>
22 
23 #include <mln/pw/all.hh>
24 
25 #include <tests/data.hh>
26 #include <doc/tools/sample_utils.hh>
27 
28 namespace mln
29 {
30 
31  template <typename I, typename N>
32  mln_concrete(I)
33  my_algorithm(const Image<I>& ima_,
34  const Neighborhood<N>& nbh_)
35  {
36  trace::entering("my_algorithm");
37 
38  const I& ima = exact(ima_);
39  const N& nbh = exact(nbh_);
40  mln_precondition(ima.is_valid());
41  mln_precondition(nbh.is_valid());
42 
43  typedef value::label_8 V;
44  V nlabels;
45  mln_ch_value(I,V) lbl = labeling::blobs(ima, nbh, nlabels);
46  util::array<unsigned>
47  count = labeling::compute(accu::meta::math::count(),
48  lbl,
49  nlabels);
50 
51  mln_concrete(I) output;
52  initialize(output, ima);
53  data::fill(output, literal::one);
54 
55  for (unsigned i = 1; i <= nlabels; ++i)
56  if (count[i] < 10u)
57  data::fill((output | (pw::value(lbl) == pw::cst(i))).rw(),
58  literal::zero);
59 
60  trace::exiting("my_algorithm");
61  return output;
62  }
63 
64 } // end of namespace mln
65 // \}
66 
67 namespace sandbox
68 {
69 
70  using namespace mln;
71 
72  // \{
73  template <typename I, typename N>
74  mln_concrete(I)
75  my_algorithm(const Image<I>& ima_,
76  const Neighborhood<N>& nbh_)
77  // \}
78  {
79  // \{
80  trace::entering("my_algorithm");
81  // \}
82 
83  // \{
84  const I& ima = exact(ima_);
85  const N& nbh = exact(nbh_);
86  mln_precondition(ima.is_valid());
87  mln_precondition(nbh.is_valid());
88  // \}
89 
90  // \{
91  typedef value::label_8 V;
92  V nlabels;
93  mln_ch_value(I,V) lbl = labeling::blobs(ima, nbh, nlabels);
94  util::array<unsigned>
95  count = labeling::compute(accu::meta::math::count(),
96  lbl,
97  nlabels);
98  // \}
99 
100  // \{
101  mln_concrete(I) output;
102  initialize(output, ima);
103  data::fill(output, literal::one);
104  // \}
105 
106  // \{
107  for (unsigned i = 1; i <= nlabels; ++i)
108  if (count[i] < 10u)
109  data::fill((output | (pw::value(lbl) == pw::cst(i))).rw(),
110  literal::zero);
111  // \}
112 
113  // \{
114  trace::exiting("my_algorithm");
115  return output;
116  // \}
117  }
118 
119 } // end of namespace mln
120 
121 int main()
122 {
123  mln::image2d<bool> test(2,2);
124  mln_assertion(sandbox::my_algorithm(test, mln::c4())
125  == mln::my_algorithm(test, mln::c4()));
126 }