Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
morpho/tree/filter/filter.cc
1 // Copyright (C) 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/alias/neighb2d.hh>
28 #include <mln/core/var.hh>
29 #include <mln/pw/all.hh>
30 
31 #include <mln/value/int_u8.hh>
32 #include <mln/io/pgm/load.hh>
33 #include <mln/io/pgm/save.hh>
34 
35 #include <mln/morpho/tree/component_tree.hh>
36 #include <mln/morpho/tree/compute_attribute_image.hh>
37 #include <mln/morpho/attribute/card.hh>
38 
39 #include <mln/morpho/tree/filter/all.hh>
40 #include <mln/morpho/tree/propagate_representative.hh>
41 
42 #include <mln/morpho/closing/area.hh>
43 
44 #include "tests/data.hh"
45 
46 #include <iostream>
47 
48 int main()
49 {
50  using namespace mln;
51  using value::int_u8;
52 
53 
54  typedef image2d<int_u8> I;
55  I input;
56  io::pgm::load(input, MLN_IMG_DIR "/tiny.pgm");
57 
58  typedef p_array< mln_site_(I) > S;
59  typedef morpho::tree::data<I,S> tree_t;
60 
61  tree_t tree = morpho::tree::min_tree(input, c4());
62 
63  // Test with increasing attribute -> area closing.
64  {
65  typedef morpho::attribute::card<I> attribute_t;
66  typedef mln_ch_value_(I, unsigned) A;
67 
68  A a = morpho::tree::compute_attribute_image(attribute_t (), tree);
69 
70  unsigned lambda = 5;
71  mln_VAR(predicate, pw::value(a) >= pw::cst(lambda));
72  I ref = morpho::closing::area(input, c4(), lambda);
73 
74  {
75  I out = duplicate(input);
76  morpho::tree::filter::min(tree, out, predicate);
78  mln_assertion(out == ref);
79  }
80 
81  {
82  I out = duplicate(input);
83  morpho::tree::filter::max(tree, out, predicate);
85  mln_assertion(out == ref);
86  }
87 
88  {
89  I out = duplicate(input);
90  morpho::tree::filter::direct(tree, out, predicate);
92  mln_assertion(out == ref);
93  }
94 
95  // Not for subtractive strategy (removal procedure differs).
96  }
97 }