$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
chamfer.cc
1 // Copyright (C) 2007, 2008, 2009 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 #include <mln/core/image/image2d.hh>
27 #include <mln/core/image/dmorph/sub_image.hh>
28 
29 
30 #include <mln/data/fill.hh>
31 #include <mln/debug/println.hh>
32 #include <mln/core/alias/w_window2d_int.hh>
33 #include <mln/core/alias/w_window2d_float.hh>
34 
35 #include <mln/make/win_chamfer.hh>
36 #include <mln/geom/chamfer.hh>
37 #include <mln/data/compare.hh>
38 
39 #include <mln/opt/at.hh>
40 
41 
42 int main()
43 {
44  using namespace mln;
45  unsigned max = 51;
46 
47  image2d<bool> ima(9, 9);
48 
49  {
50  data::fill(ima, false);
51  opt::at(ima, 4,4) = true;
52  const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2, 0> ();
53  image2d<unsigned> out = geom::chamfer(ima, w_win, max);
54  unsigned r[9][9] =
55  {
56  {16, 14, 12, 10, 8, 10, 12, 14, 16},
57  {14, 12, 10, 8, 6, 8, 10, 12, 14},
58  {12, 10, 8, 6, 4, 6, 8, 10, 12},
59  {10, 8, 6, 4, 2, 4, 6, 8, 10},
60  { 8, 6, 4, 2, 0, 2, 4, 6, 8},
61  {10, 8, 6, 4, 2, 4, 6, 8, 10},
62  {12, 10, 8, 6, 4, 6, 8, 10, 12},
63  {14, 12, 10, 8, 6, 8, 10, 12, 14},
64  {16, 14, 12, 10, 8, 10, 12, 14, 16}
65  };
66 
68  mln_assertion (out == ref);
69  }
70 
71  {
72  data::fill(ima, false);
73  opt::at(ima, 4,4) = true;
74  const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2, 3> ();
75  image2d<unsigned> out = geom::chamfer(ima, w_win, max);
76 
77  unsigned r[9][9] =
78  {
79  {12, 11, 10, 9, 8, 9, 10, 11, 12},
80  {11, 9, 8, 7, 6, 7, 8, 9, 11},
81  {10, 8, 6, 5, 4, 5, 6, 8, 10},
82  { 9, 7, 5, 3, 2, 3, 5, 7, 9},
83  { 8, 6, 4, 2, 0, 2, 4, 6, 8},
84  { 9, 7, 5, 3, 2, 3, 5, 7, 9},
85  {10, 8, 6, 5, 4, 5, 6, 8, 10},
86  {11, 9, 8, 7, 6, 7, 8, 9, 11},
87  {12, 11, 10, 9, 8, 9, 10, 11, 12}
88  };
89 
91  mln_assertion (out == ref);
92  }
93 
94  {
95  data::fill(ima, false);
96  opt::at(ima, 4,4) = true;
97  const w_window2d_int& w_win = make::mk_chamfer_5x5_int<4, 6, 9> ();
98  image2d<unsigned> out = geom::chamfer(ima, w_win, max);
99  image2d<unsigned>::fwd_piter p(out.domain());
100  for_all(p)
101  out(p) = out(p) / 2;
102 
103  unsigned r[9][9] =
104  {
105  {12, 10, 9, 8, 8, 8, 9, 10, 12},
106  {10, 9, 7, 6, 6, 6, 7, 9, 10},
107  { 9, 7, 6, 4, 4, 4, 6, 7, 9},
108  { 8, 6, 4, 3, 2, 3, 4, 6, 8},
109  { 8, 6, 4, 2, 0, 2, 4, 6, 8},
110  { 8, 6, 4, 3, 2, 3, 4, 6, 8},
111  { 9, 7, 6, 4, 4, 4, 6, 7, 9},
112  {10, 9, 7, 6, 6, 6, 7, 9, 10},
113  {12, 10, 9, 8, 8, 8, 9, 10, 12}
114  };
115 
117  mln_assertion (out == ref);
118 
119  }
120 
121 }