$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hit_or_miss.cc
1 // Copyright (C) 2007, 2008, 2009, 2010 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 
27 #include <mln/core/image/image2d.hh>
28 #include <mln/value/int_u8.hh>
29 
30 #include <mln/win/rectangle2d.hh>
31 #include <mln/core/alias/window2d.hh>
32 
33 #include <mln/win/shift.hh>
34 #include <mln/win/diff.hh>
35 
36 #include <mln/io/pbm/load.hh>
37 #include <mln/io/pbm/save.hh>
38 #include <mln/data/fill.hh>
39 
40 #include <mln/morpho/hit_or_miss.hh>
41 
42 # include <mln/convert/to.hh>
43 
44 #include "tests/data.hh"
45 
46 
47 int main()
48 {
49  using namespace mln;
50  using value::int_u8;
51 
52  window2d win_hit = win::shift(win::rectangle2d(3, 3),
53  dpoint2d(+1, +1));
54  window2d win_miss = win::rectangle2d(5, 5) - win_hit;
55 
56  {
57  bool hit[] = { 0, 0, 0, 0, 0,
58  0, 0, 0, 0, 0,
59  0, 0, 1, 1, 1,
60  0, 0, 1, 1, 1,
61  0, 0, 1, 1, 1 };
62  window2d win_hit_ = convert::to<window2d>(hit);
63  mln_assertion(win_hit_ == win_hit);
64 
65  bool miss[] = { 1, 1, 1, 1, 1,
66  1, 1, 1, 1, 1,
67  1, 1, 0, 0, 0,
68  1, 1, 0, 0, 0,
69  1, 1, 0, 0, 0 };
70  window2d win_miss_ = convert::to<window2d>(miss);
71  mln_assertion(win_miss_ == win_miss);
72  }
73 
75 
76  image2d<bool> pic;
77  io::pbm::load(pic, MLN_IMG_DIR "/picasso.pbm");
78  image2d<bool> out = morpho::hit_or_miss(pic, win_hit, win_miss);
79  io::pbm::save(out, "hit_or_miss-out.pbm");
80 
81  mln_postcondition(morpho::hit_or_miss(morpho::complementation(pic),
82  win_miss, win_hit) == out);
83 
84  // FIXME: Do not work if the input image is pgm!
85 }