$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
component_precise_outline.cc
1 // Copyright (C) 2011, 2013 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 // \file
27 
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/site_set/p_array.hh>
30 #include <mln/io/pbm/load.hh>
31 #include <mln/io/pgm/load.hh>
32 
33 #include <scribo/util/component_precise_outline.hh>
34 
35 #include <mln/draw/line.hh>
36 #include "tests/data.hh"
37 
38 int main()
39 {
40  using namespace mln;
41  using namespace scribo;
42 
43  static const point2d ref_compress[] = {
44  point2d(7,6), point2d(7,5),
45  point2d(6,5), point2d(6,6),
46  point2d(5,6), point2d(5,8),
47  point2d(6,8), point2d(6,9),
48  point2d(7,9), point2d(7,8),
49  point2d(8,8), point2d(8,6)
50  };
51 
52 
53  static const point2d ref_no_compress[] = {
54  point2d(7,6), point2d(7,5),
55  point2d(6,5), point2d(6,6),
56  point2d(5,6), point2d(5,7),
57  point2d(5,8), point2d(6,8),
58  point2d(6,9), point2d(7,9),
59  point2d(7,8), point2d(8,8),
60  point2d(8,7), point2d(8,6)
61  };
62 
63  static const point2d ref_lbl_no_compress[] = {
64  point2d(7,6), point2d(7,5),
65  point2d(6,5), point2d(6,6),
66  point2d(5,6), point2d(5,7),
67  point2d(5,8), point2d(6,8),
68  point2d(6,9), point2d(7,9),
69  point2d(7,8), point2d(8,8),
70  point2d(8,7), point2d(8,6)
71  };
72 
73  static const point2d ref_lbl_compress[] = {
74  point2d(7,6), point2d(7,5),
75  point2d(6,5), point2d(6,6),
76  point2d(5,6), point2d(5,8),
77  point2d(6,8), point2d(6,9),
78  point2d(7,9), point2d(7,8),
79  point2d(8,8), point2d(8,6)
80  };
81 
82 
83  // Compute an outline of a single object.
84  // Do compress output points.
85  {
86  std::string f = SCRIBO_IMG_DIR "/single_object.pbm";
87 
88  image2d<bool> input;
89  io::pbm::load(input, f);
90 
91  p_array<point2d> par = scribo::util::component_precise_outline(input);
92 
93  for (unsigned i = 0; i < par.nsites(); ++i)
94  mln_assertion(par[i] == ref_compress[i]);
95  }
96 
97  // Compute an outline of a single object.
98  // Do NOT compress output points.
99  {
100  std::string f = SCRIBO_IMG_DIR "/single_object.pbm";
101 
102  image2d<bool> input;
103  io::pbm::load(input, f);
104 
105  p_array<point2d> par = scribo::util::component_precise_outline(input, true, false);
106 
107  for (unsigned i = 0; i < par.nsites(); ++i)
108  mln_assertion(par[i] == ref_no_compress[i]);
109  }
110 
111 
112  // Compute an outline of a labeled object among others.
113  // Do NOT compress output points.
114  {
115  std::string f = SCRIBO_IMG_DIR "/several_objects.pgm";
116 
118  io::pgm::load(input, f);
119 
120  p_array<point2d> par = scribo::util::component_precise_outline(input, 1, false);
121 
122  for (unsigned i = 0; i < par.nsites(); ++i)
123  mln_assertion(par[i] == ref_lbl_no_compress[i]);
124  }
125 
126  // Compute an outline of a labeled object among others.
127  // Do compress output points.
128  {
129  std::string f = SCRIBO_IMG_DIR "/several_objects.pgm";
130 
132  io::pgm::load(input, f);
133 
134  p_array<point2d> par = scribo::util::component_precise_outline(input, 1, true);
135 
136  for (unsigned i = 0; i < par.nsites(); ++i)
137  mln_assertion(par[i] == ref_lbl_compress[i]);
138  }
139 }