Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
scale3x.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 MLN_UPSCALING_ART_SCALE3X_HH
27 # define MLN_UPSCALING_ART_SCALE3X_HH
28 
32 
33 
34 # include <mln/core/concept/box.hh>
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/alias/neighb2d.hh>
37 # include <mln/core/alias/dpoint2d.hh>
38 
39 # include <mln/extension/adjust_duplicate.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace upscaling
46  {
47 
48  namespace art
49  {
50 
62  template <typename I>
63  mln_concrete(I)
64  scale3x(const Image<I>& input);
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69 
70  template <typename I>
71  mln_concrete(I)
72  scale3x(const Image<I>& input_)
73  {
74  trace::entering("mln::upscaling::art::scale3x");
75 
76  const I& input = exact(input_);
77  mln_precondition(input.is_valid());
78  mlc_is_a(mln_domain(I), Box)::check();
79 
81 
82  mln_domain(I) ext_domain(input.domain().pmin() * 3,
83  input.domain().pmax() * 3
84  + 2 * mln::down_right);
85 
86  mln_concrete(I) output(ext_domain);
87 
88 
89  mln_piter(I) p(input.domain());
90  for_all(p)
91  {
92 
93  // A B C --\ 1 2 3
94  // D E F > 4 5 6
95  // G H I --/ 7 8 9
96  mln_site(I)
97  pA = p + mln::up_left,
98  pB = p + mln::up,
99  pC = p + mln::up_right,
100  pD = p + mln::left,
101  pE = p,
102  pF = p + mln::right,
103  pG = p + mln::down_left,
104  pH = p + mln::down,
105  pI = p + mln::down_right,
106  pOut = p * 3 + mln::down_right;
107 
108  // IF D==B AND D!=H AND B!=F => 1=D
109  if (input(pD) == input(pB)
110  && input(pD) != input(pH)
111  && input(pB) != input(pF))
112  output(pOut + mln::up_left) = input(pD);
113  else
114  output(pOut + mln::up_left) = input(p);
115 
116  // IF (D==B AND D!=H AND B!=F AND E!=C) OR (B==F AND B!=D
117  // AND F!=H AND E!=A) 2=B
118  if ((input(pD) == input(pB)
119  && input(pD) != input(pH)
120  && input(pB) != input(pF)
121  && input(pE) != input(pC))
122  || (input(pB) == input(pF)
123  && input(pB) != input(pD)
124  && input(pF) != input(pH)
125  && input(pE) != input(pA)))
126  output(pOut + mln::up) = input(pB);
127  else
128  output(pOut + mln::up) = input(p);
129 
130  // IF B==F AND B!=D AND F!=H => 3=F
131  if (input(pB) == input(pF)
132  && input(pB) != input(pD)
133  && input(pF) != input(pH))
134  output(pOut + mln::up_right) = input(pF);
135  else
136  output(pOut + mln::up_right) = input(p);
137 
138  // IF (H==D AND H!=F AND D!=B AND E!=A) OR (D==B AND D!=H
139  // AND B!=F AND E!=G) 4=D
140  if ((input(pH) == input(pD)
141  && input(pH) != input(pF)
142  && input(pD) != input(pB)
143  && input(pE) != input(pA))
144  || (input(pD) == input(pB)
145  && input(pD) != input(pH)
146  && input(pB) != input(pF)
147  && input(pE) != input(pG)))
148  output(pOut + mln::left) = input(pD);
149  else
150  output(pOut + mln::left) = input(p);
151 
152  // 5=E
153  output(pOut) = input(p);
154 
155  // IF (B==F AND B!=D AND F!=H AND E!=I) OR (F==H AND F!=B
156  // AND H!=D AND E!=C) 6=F
157  if ((input(pB) == input(pF)
158  && input(pB) != input(pD)
159  && input(pF) != input(pH)
160  && input(pE) != input(pI))
161  || (input(pF) == input(pH)
162  && input(pF) != input(pB)
163  && input(pH) != input(pD)
164  && input(pE) != input(pC)))
165  output(pOut + mln::right) = input(pF);
166  else
167  output(pOut + mln::right) = input(p);
168 
169  // IF H==D AND H!=F AND D!=B => 7=D
170  if (input(pH) == input(pD)
171  && input(pH) != input(pF)
172  && input(pD) != input(pB))
173  output(pOut + mln::down_left) = input(pD);
174  else
175  output(pOut + mln::down_left) = input(p);
176 
177 
178  // IF (F==H AND F!=B AND H!=D AND E!=G) OR (H==D AND H!=F
179  // AND D!=B AND E!=I) 8=H
180  if ((input(pF) == input(pH)
181  && input(pF) != input(pB)
182  && input(pH) != input(pD)
183  && input(pE) != input(pG))
184  || (input(pH) == input(pD)
185  && input(pH) != input(pF)
186  && input(pD) != input(pB)
187  && input(pE) != input(pI)))
188  output(pOut + mln::down) = input(pH);
189  else
190  output(pOut + mln::down) = input(p);
191 
192 
193  // IF F==H AND F!=B AND H!=D => 9=F
194  if (input(pF) == input(pH)
195  && input(pF) != input(pB)
196  && input(pH) != input(pD))
197  output(pOut + mln::down_right) = input(pF);
198  else
199  output(pOut + mln::down_right) = input(p);
200 
201  }
202 
203  trace::exiting("mln::upscaling::art::scale3x");
204  return output;
205  }
206 
207 
208 # endif // ! MLN_INCLUDE_ONLY
209 
210 
211  } // end of namespace mln::upscaling::art
212 
213  } // end of namespace mln::upscaling
214 
215 } // end of namespace mln
216 
217 
218 #endif // ! MLN_UPSCALING_ART_SCALE3X_HH