$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
scale3x.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_SCALE3X_HH
28 # define MLN_UPSCALING_ART_SCALE3X_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  scale3x(const Image<I>& input);
67 
68 
69 # ifndef MLN_INCLUDE_ONLY
70 
71 
72  template <typename I>
73  mln_concrete(I)
74  scale3x(const Image<I>& input_)
75  {
76  mln_trace("mln::upscaling::art::scale3x");
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() * 3,
85  input.domain().pmax() * 3
86  + 2 * mln::down_right);
87 
88  mln_concrete(I) output(ext_domain);
89 
90 
91  mln_piter(I) p(input.domain());
92  for_all(p)
93  {
94 
95  // A B C --\ 1 2 3
96  // D E F > 4 5 6
97  // G H I --/ 7 8 9
98  mln_site(I)
99  pA = p + mln::up_left,
100  pB = p + mln::up,
101  pC = p + mln::up_right,
102  pD = p + mln::left,
103  pE = p,
104  pF = p + mln::right,
105  pG = p + mln::down_left,
106  pH = p + mln::down,
107  pI = p + mln::down_right,
108  pOut = p * 3 + mln::down_right;
109 
110  // IF D==B AND D!=H AND B!=F => 1=D
111  if (input(pD) == input(pB)
112  && input(pD) != input(pH)
113  && input(pB) != input(pF))
114  output(pOut + mln::up_left) = input(pD);
115  else
116  output(pOut + mln::up_left) = input(p);
117 
118  // IF (D==B AND D!=H AND B!=F AND E!=C) OR (B==F AND B!=D
119  // AND F!=H AND E!=A) 2=B
120  if ((input(pD) == input(pB)
121  && input(pD) != input(pH)
122  && input(pB) != input(pF)
123  && input(pE) != input(pC))
124  || (input(pB) == input(pF)
125  && input(pB) != input(pD)
126  && input(pF) != input(pH)
127  && input(pE) != input(pA)))
128  output(pOut + mln::up) = input(pB);
129  else
130  output(pOut + mln::up) = input(p);
131 
132  // IF B==F AND B!=D AND F!=H => 3=F
133  if (input(pB) == input(pF)
134  && input(pB) != input(pD)
135  && input(pF) != input(pH))
136  output(pOut + mln::up_right) = input(pF);
137  else
138  output(pOut + mln::up_right) = input(p);
139 
140  // IF (H==D AND H!=F AND D!=B AND E!=A) OR (D==B AND D!=H
141  // AND B!=F AND E!=G) 4=D
142  if ((input(pH) == input(pD)
143  && input(pH) != input(pF)
144  && input(pD) != input(pB)
145  && input(pE) != input(pA))
146  || (input(pD) == input(pB)
147  && input(pD) != input(pH)
148  && input(pB) != input(pF)
149  && input(pE) != input(pG)))
150  output(pOut + mln::left) = input(pD);
151  else
152  output(pOut + mln::left) = input(p);
153 
154  // 5=E
155  output(pOut) = input(p);
156 
157  // IF (B==F AND B!=D AND F!=H AND E!=I) OR (F==H AND F!=B
158  // AND H!=D AND E!=C) 6=F
159  if ((input(pB) == input(pF)
160  && input(pB) != input(pD)
161  && input(pF) != input(pH)
162  && input(pE) != input(pI))
163  || (input(pF) == input(pH)
164  && input(pF) != input(pB)
165  && input(pH) != input(pD)
166  && input(pE) != input(pC)))
167  output(pOut + mln::right) = input(pF);
168  else
169  output(pOut + mln::right) = input(p);
170 
171  // IF H==D AND H!=F AND D!=B => 7=D
172  if (input(pH) == input(pD)
173  && input(pH) != input(pF)
174  && input(pD) != input(pB))
175  output(pOut + mln::down_left) = input(pD);
176  else
177  output(pOut + mln::down_left) = input(p);
178 
179 
180  // IF (F==H AND F!=B AND H!=D AND E!=G) OR (H==D AND H!=F
181  // AND D!=B AND E!=I) 8=H
182  if ((input(pF) == input(pH)
183  && input(pF) != input(pB)
184  && input(pH) != input(pD)
185  && input(pE) != input(pG))
186  || (input(pH) == input(pD)
187  && input(pH) != input(pF)
188  && input(pD) != input(pB)
189  && input(pE) != input(pI)))
190  output(pOut + mln::down) = input(pH);
191  else
192  output(pOut + mln::down) = input(p);
193 
194 
195  // IF F==H AND F!=B AND H!=D => 9=F
196  if (input(pF) == input(pH)
197  && input(pF) != input(pB)
198  && input(pH) != input(pD))
199  output(pOut + mln::down_right) = input(pF);
200  else
201  output(pOut + mln::down_right) = input(p);
202 
203  }
204 
205  return output;
206  }
207 
208 
209 # endif // ! MLN_INCLUDE_ONLY
210 
211 
212  } // end of namespace mln::upscaling::art
213 
214  } // end of namespace mln::upscaling
215 
216 } // end of namespace mln
217 
218 
219 #endif // ! MLN_UPSCALING_ART_SCALE3X_HH