$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
make_complex2d.hh
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 #ifndef APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
27 # define APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
28 
31 
32 # include <mln/core/image/image2d.hh>
33 # include <mln/world/inter_pixel/dim2/is_pixel.hh>
34 
44 template <typename I>
45 inline
46 mln_concrete(I)
47 make_complex2d(const mln::Image<I>& input_)
48 {
49  using namespace mln;
50 
51  const I& input = exact(input_);
52  /* FIXME: The construction of OUTPUT is obvioulsy not generic, since
53  it expects I's domain to provide the interface of an mln::box2d.
54  There should be a static precondition on I at the beginning of
55  this function. */
56  typedef mln_concrete(I) O;
57  O output(2 * input.nrows() - 1, 2 * input.ncols() - 1);
58 
59  mln_piter(O) p(output.domain());
60  for_all(p)
61  {
62  point2d p_ = p;
63  if (p_.row() % 2 == 0)
64  {
65  if (p_.col() % 2 == 0)
66  // Pixel site.
67  output(p) = input.at_(p_.row() / 2, p_.col() / 2);
68  else
69  // Horizontal edge site.
70  output(p) =
71  input.at_(p_.row() / 2, (p_.col() - 1) / 2) &&
72  input.at_(p_.row() / 2, (p_.col() + 1) / 2);
73  }
74  else
75  {
76  if (p_.col() % 2 == 0)
77  // Vertical edge site.
78  output(p) =
79  input.at_((p_.row() - 1) / 2, p_.col() / 2) &&
80  input.at_((p_.row() + 1) / 2, p_.col() / 2);
81  else
82  // Square site (not handled, but still set for possible
83  // debug outputs).
84  output(p) =
85  input.at_((p_.row() - 1) / 2, (p_.col() - 1) / 2) &&
86  input.at_((p_.row() - 1) / 2, (p_.col() + 1) / 2) &&
87  input.at_((p_.row() + 1) / 2, (p_.col() - 1) / 2) &&
88  input.at_((p_.row() + 1) / 2, (p_.col() + 1) / 2);
89  }
90  }
91  return output;
92 }
93 
94 
100 template <typename I>
101 inline
102 mln_concrete(I)
103 unmake_complex2d(const mln::Image<I>& input_)
104 {
105  using namespace mln;
106 
107  const I& input = exact(input_);
108  // The input image must have an odd number of rows and columns.
109  mln_precondition(input.nrows() % 2 == 1);
110  mln_precondition(input.ncols() % 2 == 1);
111 
112  // Create a (morpher) image of the pixels of INPUT.
114  J input_pixels = input | world::inter_pixel::dim2::is_pixel();
115 
116  /* FIXME: The construction of OUTPUT is obvioulsy not generic, since
117  it expects I's domain to provide the interface of an mln::box2d.
118  There should be a static precondition on I at the beginning of
119  this function. */
120  typedef mln_concrete(I) O;
121  // FIXME: This won't work if INPUT's domain does not start at (0,0).
122  O output(input.nrows() / 2 + 1, input.ncols() / 2 + 1);
123 
124  mln_piter(J) p_in(input_pixels.domain());
125  mln_piter(O) p_out(output.domain());
126  for_all_2(p_in, p_out)
127  output(p_out) = input(p_in);
128  return output;
129 }
130 
131 
132 #endif // ! APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH