$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
eagle.hh
1 // Copyright (C) 2010 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 SCRIBO_UPSAMPLING_EAGLE_HH_
27 # define SCRIBO_UPSAMPLING_EAGLE_HH_
28 
32 
33 # include <mln/core/concept/image.hh>
34 # include <mln/core/def/coord.hh>
35 # include <mln/geom/min_row.hh>
36 # include <mln/geom/min_col.hh>
37 # include <mln/geom/max_row.hh>
38 # include <mln/geom/max_col.hh>
39 # include <mln/opt/at.hh>
40 # include <mln/make/box2d.hh>
41 
42 namespace scribo
43 {
44 
45  namespace upsampling
46  {
47 
48  using namespace mln;
49 
52  //
53  template <typename I>
54  mln_concrete(I)
55  eagle(const Image<I>& ima);
56 
57 
58 
59 # ifndef MLN_INCLUDE_ONLY
60 
61 
62  template <typename I>
63  mln_concrete(I)
64  eagle(const Image<I>& input_)
65  {
66  mln_trace("scribo::upsampling::eagle");
67 
68  typedef mln_value(I) V;
69  const I& input = exact(input_);
70 
71  mln_precondition(input.is_valid());
72 
73  mln::def::coord
74  mrow = geom::min_row(input),
75  mcol = geom::min_col(input),
76  mxrow = geom::max_row(input),
77  mxcol = geom::max_col(input);
78 
79 
80  mln_piter(I) p(input.domain());
81  mln_concrete(I)
82  output(mln::make::box2d(mrow, mcol,
83  mrow + 2 * input.nrows() - 1,
84  mcol + 2 * input.ncols() - 1));
85 
86  for_all(p)
87  {
89  prow = p.row() - mrow,
90  pcol = p.col() - mcol;
91 
92  if (p.row() == mrow
93  || p.col() == mcol
94  || p.row() == mxrow
95  || p.col() == mxcol)
96  {
97  box2d b = mln::make::box2d(2 * prow, 2 * pcol,
98  2 * prow + 1, 2 * pcol + 1);
99  mln_piter_(box2d) pb(b);
100  V value = opt::at(input, p.row(), p.col());
101 
102  for_all(pb)
103  opt::at(output, mrow + pb.row(), mcol + pb.col()) = value;
104  }
105  else
106  {
107  V
108  n = opt::at(input, p.row() - 1, p.col()),
109  s = opt::at(input, p.row() + 1, p.col()),
110  e = opt::at(input, p.row(), p.col() + 1),
111  w = opt::at(input, p.row(), p.col() - 1),
112  nw = opt::at(input, p.row() - 1, p.col() - 1),
113  ne = opt::at(input, p.row() - 1, p.col() + 1),
114  sw = opt::at(input, p.row() + 1, p.col() - 1),
115  se = opt::at(input, p.row() + 1, p.col() + 1),
116  value = opt::at(input, p.row(), p.col());
117 
118  if (e != w || n != s || e != n)
119  {
120  opt::at(output, mrow + 2 * prow, mcol + 2 * pcol) = ((w == n && w == nw && nw == n) ? nw : value);
121  opt::at(output, mrow + 2 * prow, mcol + 2 * pcol + 1) = ((e == n && e == ne && ne == n) ? ne : value);
122  opt::at(output, mrow + 2 * prow + 1, mcol + 2 * pcol) = ((w == s && w == sw && sw == s) ? sw : value);
123  opt::at(output, mrow + 2 * prow + 1, mcol + 2 * pcol + 1) = ((e == s && e == se && se == s) ? se : value);
124  }
125  else
126  {
127  box2d b = mln::make::box2d(2 * prow, 2 * pcol,
128  2 * prow + 1, 2 * pcol + 1);
129  mln_piter_(box2d) pb(b);
130  V value = opt::at(input, p.row(), p.col());
131 
132  for_all(pb)
133  opt::at(output, mrow + pb.row(), mcol + pb.col()) = value;
134  }
135  }
136  }
137 
138  return output;
139  }
140 
141 # endif // ! MLN_INCLUDE_ONLY
142 
143 
144  } // end of namespace upsampling
145 
146 } // end of namespace scribo
147 
148 #endif // ! SCRIBO_UPSAMPLING_EAGLE_HH_