$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
scale2x.hh
1 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_UPSCALING_ART_SCALE2X_HH
28 # define MLN_UPSCALING_ART_SCALE2X_HH
29 
33 
34 
35 # include <mln/core/concept/box.hh>
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/alias/neighb2d.hh>
38 # include <mln/core/alias/dpoint2d.hh>
39 
40 # include <mln/extension/adjust_duplicate.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace upscaling
47  {
48 
49  namespace art
50  {
51 
64  template <typename I>
65  mln_concrete(I)
66  scale2x(const Image<I>& input);
67 
68 
69 # ifndef MLN_INCLUDE_ONLY
70 
71 
72  template <typename I>
73  mln_concrete(I)
74  scale2x(const Image<I>& input_)
75  {
76  mln_trace("mln::upscaling::art::scale2x");
77 
78  const I& input = exact(input_);
79  mln_precondition(input.is_valid());
80  mlc_is_a(mln_domain(I), Box)::check();
81 
83 
84  mln_domain(I) ext_domain(input.domain().pmin() * 2,
85  input.domain().pmax() * 2
86  + mln::down_right);
87 
88  mln_concrete(I) output(ext_domain);
89 
90  mln_piter(I) p(input.domain());
91  for_all(p)
92  {
93 
94  // A --\ 1 2
95  // C P B --/ 3 4
96  // D
97  mln_site(I)
98  pA = p + mln::up,
99  pB = p + mln::right,
100  pC = p + mln::left,
101  pD = p + mln::down,
102  pOut = p * 2;
103 
104  // IF C==A AND C!=D AND A!=B => 1=A
105  if (input(pC) == input(pA)
106  && input(pC) != input(pD)
107  && input(pA) != input(pB))
108  output(pOut) = input(pA);
109  else
110  output(pOut) = input(p);
111 
112  // IF A==B AND A!=C AND B!=D => 2=B
113  if (input(pA) == input(pB)
114  && input(pA) != input(pC)
115  && input(pB) != input(pD))
116  output(pOut + mln::right) = input(pB);
117  else
118  output(pOut + mln::right) = input(p);
119 
120  // IF D==C AND D!=B AND C!=A => 3=C
121  if (input(pD) == input(pC)
122  && input(pD) != input(pB)
123  && input(pC) != input(pA))
124  output(pOut + mln::down) = input(pC);
125  else
126  output(pOut + mln::down) = input(p);
127 
128  // IF B==D AND B!=A AND D!=C => 4=D
129  if (input(pB) == input(pD)
130  && input(pB) != input(pA)
131  && input(pD) != input(pC))
132  output(pOut + mln::down_right) = input(pD);
133  else
134  output(pOut + mln::down_right) = input(p);
135 
136  }
137 
138  return output;
139  }
140 
141 
142 # endif // ! MLN_INCLUDE_ONLY
143 
144 
145  } // end of namespace mln::upscaling::art
146 
147  } // end of namespace mln::upscaling
148 
149 } // end of namespace mln
150 
151 
152 #endif // ! MLN_UPSCALING_ART_SCALE2X_HH