$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
apps/papers/levillain.09.ismm/image2d.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 <cstdlib>
27 
28 #include <string>
29 
30 #include <mln/core/image/image2d.hh>
31 #include <mln/core/alias/neighb2d.hh>
32 #include <mln/core/alias/window2d.hh>
33 
34 #include <mln/value/int_u8.hh>
35 #include <mln/value/label_8.hh>
36 
37 #include <mln/morpho/gradient.hh>
38 
39 #include <mln/io/pgm/load.hh>
40 #include <mln/io/pgm/save.hh>
41 #include <mln/io/ppm/save.hh>
42 #include <mln/labeling/colorize.hh>
43 
44 #include "chain.hh"
45 
46 int main(int argc, char* argv[])
47 {
48  if (argc != 4)
49  {
50  std::cerr << "usage: " << argv[0] << " input.pgm lambda output.ppm"
51  << std::endl;
52  std::exit(1);
53  }
54  std::string input_filename = argv[1];
55  unsigned lambda = atoi(argv[2]);
56  std::string output_filename = argv[3];
57 
58  using namespace mln;
59 
60  typedef value::int_u8 val;
61  typedef value::label_8 label;
62  // Input and output types.
63  typedef image2d<val> input;
64  typedef mln_ch_value_(input, label) output;
65  neighb2d nbh = c4();
66  window2d win = win_c4p();
67  label nbasins;
68 
69  std::cout << c4() << std::endl;
70  std::cout << win_c4p() << std::endl;
71 
72  // Load, process, save.
73  input ima = io::pgm::load<val>(input_filename);
74  // Gradient.
75  /* FIXME: Unfortunately, we cannot write
76 
77  morpho::gradient(ima, win)
78 
79  here, since MM only uses windows (yet?), not neighborhoods. And
80  we cannot either write
81 
82  morpho::gradient(ima, nbh.win()),
83 
84  since that window would not contain the center site...
85  Therefore, this function asks for a window WIN matching the
86  neighborhood NBH, plus the center site.
87 
88  A neighborhood `n' should provide a method `win_p()' returning a
89  window corresponding to `n' plus the center site. */
90  input g = morpho::gradient(ima, win);
91 
92 #if 0
93  // FIXME: get the name as argument.
94  io::pgm::save(g, "apps/lena-g.pgm");
95 #endif
96 
97  // Chain.
98  output s = chain(g, nbh, lambda, nbasins);
100  output_filename);
101 }