$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stretch_full.cc
1 // Copyright (C) 2007, 2008, 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 #include <mln/core/image/image1d.hh>
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/image/image3d.hh>
29 
30 #include <mln/value/int_u8.hh>
31 #include <mln/value/int_s8.hh>
32 #include <mln/value/int_u16.hh>
33 #include <mln/value/int_s16.hh>
34 
35 #include <mln/debug/iota.hh>
36 #include <mln/data/saturate.hh>
37 #include <mln/data/stretch.hh>
38 
39 
40 
41 namespace mln
42 {
43  template <typename I, typename J>
44  void
45  chck(Image<I>& input_, Image<J>& output_)
46  {
47  I& input = exact(input_);
48  J& output = exact(output_);
49  output = data::stretch(mln_value(J)(), input);
50  }
51 
52  template <typename I, typename J>
53  void
54  chk1d(unsigned cols)
55  {
56  {
57  image1d<I> input(cols);
58  debug::iota(input);
59  image1d<J> output(cols);
60  chck(input, output);
61  }
62 
63  }
64 
65  template <typename I, typename J>
66  void
67  chk2d(unsigned rows, unsigned cols)
68  {
69 
70  {
71  image2d<I> input(rows, cols);
72  debug::iota(input);
73  image2d<J> output(rows, cols);
74  chck(input, output);
75  }
76 
77  }
78 
79  template <typename I, typename J>
80  void
81  chk3d(unsigned slis, unsigned rows, unsigned cols)
82  {
83 
84  {
85  image3d<I> input(slis, rows, cols);
86  debug::iota(input);
87  image3d<J> output(slis, rows, cols);
88  chck(input, output);
89  }
90 
91  }
92 
93 
94  template <typename I, typename J>
95  void
96  chk(unsigned slis, unsigned rows, unsigned cols)
97  {
98  (std::cerr << " in 1d ... ").flush ();
99  {
100  for (unsigned i = 2; i < cols; ++i)
101  chk1d<I, J>(i);
102  }
103  std::cerr << "OK" << std::endl;
104 
105  (std::cerr << " in 2d ... ").flush ();
106  {
107  for (unsigned j = 2; j < rows; ++j)
108  for (unsigned i = 2; i < cols; ++i)
109  chk2d<I, J>(j, i);
110  }
111  std::cerr << "OK" << std::endl;
112 
113  (std::cerr << " in 3d ... ").flush ();
114  {
115  for (unsigned k = 2; k < slis; ++k)
116  for (unsigned j = 2; j < rows; ++j)
117  for (unsigned i = 2; i < cols; ++i)
118  chk3d<I, J>(k, j, i);
119  }
120  std::cerr << "OK" << std::endl;
121  }
122 
123  template <typename I>
124  void
125  ch(unsigned slis, unsigned rows, unsigned cols)
126  {
127  std::cerr << " into int_u8:" << std::endl;
128  chk<I, value::int_u8>(slis, rows, cols);
129  std::cerr << " into int_u16:" << std::endl;
130  chk<I, value::int_u16>(slis, rows, cols);
131  }
132 }
133 
134 
135 int main()
136 {
137  using namespace mln;
138 
139  unsigned slis = 4;
140  unsigned rows = 4;
141  unsigned cols = 16;
142 
143  std::cerr << "Tests data::stretch:" << std::endl;
144  std::cerr << "on int:" << std::endl;
145  ch<int>(slis, rows, cols);
146  std::cerr << "on unsigned:" << std::endl;
147  ch<unsigned>(slis, rows, cols);
148  std::cerr << "on int_u8:" << std::endl;
149  ch<value::int_u8>(slis, rows, cols);
150  std::cerr << "on int_u16:" << std::endl;
151  ch<value::int_u16>(slis, rows, cols);
152  std::cerr << "on int_s8:" << std::endl;
153  ch<value::int_s8>(slis, rows, cols);
154  std::cerr << "on int_s16:" << std::endl;
155  ch<value::int_s16>(slis, rows, cols);
156 }