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