$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
extract_lines_with_rank.cc
1 // Copyright (C) 2009, 2010 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 #include <mln/core/image/image2d.hh>
28 #include <mln/core/alias/box2d.hh>
29 #include <mln/make/box2d.hh>
30 #include <mln/util/array.hh>
31 #include <mln/util/couple.hh>
32 #include <mln/io/pbm/load.hh>
33 #include <mln/value/label_8.hh>
34 #include <mln/win/vline2d.hh>
35 #include <mln/win/hline2d.hh>
36 #include <mln/core/alias/neighb2d.hh>
37 
38 #include <mln/literal/colors.hh>
39 
40 #include <mln/io/pgm/save.hh>
41 
42 #include <scribo/primitive/extract/lines_h_discontinued.hh>
43 #include <scribo/primitive/extract/lines_v_discontinued.hh>
44 
45 #include "tests/data.hh"
46 
47 
48 int main(int argc, char *argv[])
49 {
50  using namespace mln;
51 
52  std::string img;
53  if (argc < 2)
54  img = SCRIBO_IMG_DIR "/table_to_be_repaired.pbm";
55  else
56  img = argv[1];
57 
58  image2d<bool> input;
59  io::pbm::load(input, img.c_str());
60 
61  typedef util::array<box2d> lineboxes_t;
62 
63  lineboxes_t
64  vboxes,
65  hboxes;
66  vboxes.append(make::box2d(0,0, 59,59));
67  vboxes.append(make::box2d(0,28, 27, 32));
68  vboxes.append(make::box2d(31,28, 59,32));
69  hboxes.append(make::box2d(0,0, 59,59));
70  hboxes.append(make::box2d(27,0, 31, 26));
71  hboxes.append(make::box2d(27,34, 31,59));
72 
73  value::label_8 nbboxes;
74 
75  lineboxes_t hboxes_, vboxes_;
76 
77  typedef object_image(image2d<value::label_8>) lbl_t;
78  lbl_t
79  hlbl = scribo::primitive::extract::lines_h_discontinued(input, c8(),
80  nbboxes, 11, 2);
81  lbl_t
82  vlbl = scribo::primitive::extract::lines_v_discontinued(input, c8(),
83  nbboxes, 11, 2);
84  mln_assertion(hlbl.nlabels() == 2);
85  mln_assertion(vlbl.nlabels() == 2);
86  // Background values are meaningless, we skip them.
87  for (unsigned i = 1; i < 3; ++i)
88  {
89  mln_assertion(hlbl.bbox(i) == hboxes(i));
90  mln_assertion(vlbl.bbox(i) == vboxes(i));
91  }
92 
93 }