$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compute_local_configurations.cc
1 // Copyright (C) 2008, 2009, 2011 EPITA Research and Development
2 // Laboratory (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 
28 
29 #include <iostream>
30 #include <iomanip>
31 
32 #include <mln/core/image/image2d.hh>
33 #include <mln/core/alias/neighb2d.hh>
34 #include <mln/value/int_u8.hh>
35 
36 #include <mln/labeling/blobs.hh>
37 #include <mln/data/fill.hh>
38 #include <mln/debug/println.hh>
39 
40 
41 int main()
42 {
43  using namespace mln;
44  using value::int_u8;
45 
46  typedef image2d<bool> I;
47 
48  box2d b = make::box2d(-1,-1, 1,1);
49  image2d<bool> ima(b, 0);
50  point2d p(0, 0);
51 
52  std::vector<int_u8> x8(256), x4(256);
53 
54 
55  for (unsigned i = 0; i < 256; i++)
56  {
57  /* Create the local i-th configuration around P.
58 
59  Note that the value corresponding to P is always `false', to
60  prevent the connection of two components through P. */
61  data::fill(ima, false);
62  int_u8 tmp = i;
63  mln_fwd_niter_(neighb2d) n(c8(), p);
64  for_all(n)
65  {
66  // Inspect the least significant bit.
67  if (tmp % 2)
68  ima(n) = true;
69  tmp = tmp >> 1;
70  }
71 
72  labeling::blobs(ima, c8(), x8[i]);
73 
74  {
75  int_u8 nl;
76  image2d<int_u8> lab = labeling::blobs(ima, c4(), nl);
77  std::set<int_u8> s;
78  mln_fwd_niter_(neighb2d) n(c4(), p);
79  for_all(n)
80  if (lab(n) != 0)
81  s.insert(lab(n));
82  x4[i] = s.size();
83  }
84  }
85 
86 
87  // Now printing!
88 
89  std::cout << "----- Object in C8 ------" << std::endl;
90 
91  for (unsigned i = 0; i < 256; i++)
92  {
93  std::cout << std::setw(2) << x8[i] << ", ";
94  if (! ((i + 1) % 4)) std::cout << " ";
95  if (! ((i + 1) % 16)) std::cout << std::endl;
96  if (! ((i + 1) % 64)) std::cout << std::endl;
97  }
98 
99  std::cout << "----- Object in C4 ------" << std::endl;
100 
101  for (unsigned i = 0; i < 256; i++)
102  {
103  std::cout << std::setw(2) << x4[i] << ", ";
104  if (! ((i + 1) % 4)) std::cout << " ";
105  if (! ((i + 1) % 16)) std::cout << std::endl;
106  if (! ((i + 1) % 64)) std::cout << std::endl;
107  }
108 
109 }