$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fld2d.cc
1 // Copyright (C) 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (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 
30 
31 #include <mln/core/image/image2d.hh>
32 
33 #include <mln/io/pgm/load.hh>
34 #include <mln/io/ppm/load.hh>
35 #include <mln/io/fld/load.hh>
36 #include <mln/io/fld/save.hh>
37 #include <mln/value/int_u8.hh>
38 #include <mln/value/int_u16.hh>
39 #include <mln/data/compare.hh>
40 #include "tests/data.hh"
41 
42 #include <stdio.h>
43 #include <float.h>
44 #include <time.h>
45 
46 int main()
47 {
48  using namespace mln;
49  using value::int_u8;
50  using value::int_u16;
51 
52  // Test on int_u8.
53  // Veclen = 1, data = byte
54  {
55  image2d<int_u8> ori, test;
56  io::pgm::load(ori, MLN_IMG_DIR "/lena.pgm");
57 
58  io::fld::save(ori, "out2d.fld");
59  io::fld::load(test, "out2d.fld");
60 
61  // Clean output.
62  std::remove("out2d.fld");
63 
64  mln_assertion(ori == test);
65  }
66 
67  // Test on RGB 16
68  // Veclen = 3, data = short
69  {
71  io::ppm::load(ori, MLN_IMG_DIR "/lena_16.ppm");
72 
73  io::fld::save(ori, "out2d.fld");
74  io::fld::load(test, "out2d.fld");
75 
76  // Clean output.
77  std::remove("out2d.fld");
78 
79  mln_assertion(ori == test);
80  }
81 
82  // Test on 32-bits data type
83  // Veclen = 1, data = float
84  {
85  image2d<float> ori, test;
86  box<point2d> domain(8, 9);
87 
88  srand(time(NULL));
89  ori.init_(domain);
90  {
91  mln_piter_(image2d<float>) p(domain);
92  for_all(p)
93  ori(p) = random() / RAND_MAX;
94  }
95 
96  io::fld::save(ori, "out2d.fld");
97  io::fld::load(test, "out2d.fld");
98 
99  // Clean output.
100  std::remove("out2d.fld");
101 
102  {
103  mln_piter_(image2d<float>) p(domain);
104  for_all(p)
105  mln_assertion(fabs(ori(p) - test(p)) < FLT_EPSILON);
106  }
107  }
108 
109 }