$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fft.cc
1 // Copyright (C) 2004, 2012, 2014 EPITA Research and Development Laboratory.
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/transform/fft.hh>
27 #include <mln/value/int_u8.hh>
28 #include <mln/io/pgm/load.hh>
29 #include <mln/io/pgm/save.hh>
30 #include <mln/opt/at.hh>
31 #include <mln/debug/println.hh>
32 
33 #include <mln/core/image/flat_image.hh>
34 #include <mln/fun/vv2b/le.hh>
35 #include <mln/fun/vv2v/diff_abs.hh>
36 #include <mln/data/transform.hh>
37 #include <mln/test/predicate.hh>
38 
39 #include "tests/data.hh"
40 
41 #define CHECK(Condition) \
42  if (Condition) \
43  std::cout << "OK" << std::endl; \
44  else \
45  { \
46  std::cout << "FAIL" << std::endl; \
47  status = 1; \
48  }
49 
50 using namespace mln;
51 using namespace transform;
52 using namespace value;
53 
54 int main ()
55 {
56  int status = 0;
57 
58  image2d<int_u8> im1;
59  io::pgm::load(im1, MLN_IMG_DIR "/lena.pgm");
60 
61  fft<double> fourier(im1);
62 
63  image2d< std::complex<double> > im2 = fourier.transform();
64 
65  image2d<int_u8> im3 = fourier.transform_inv<int_u8>();
66 
67  io::pgm::save(im3, "fft_copy.pgm");
68 
69  image2d<int_u8> fft = fourier.transformed_image_log_magn<int_u8>(true);
70  io::pgm::save(fft, "fft.pgm");
71 
72  std::cout << "Test: Image == F-1(F(Image)) ... " << std::flush;
73  /* FIXME: Milena lacks some feature to make write the following in a
74  shorter fashion (fun-morpher accepting binary (vv2v) functions or
75  function composition in pw-functions. */
76  CHECK(test::predicate(data::transform(im1, im3,
80 
81  image2d<int_u8> out = fourier.transformed_image_clipped_magn<int_u8>(0.01);
82 
83  io::pgm::save(out, "fft_trans_clipped.pgm");
84 
85  out = fourier.transformed_image_log_magn<int_u8>(1, 100);
86 
87  io::pgm::save(out, "fft_trans_log.pgm");
88 
89  int nrows = im2.nrows();
90  int ncols = im2.ncols();
91  int hlen = 40;
92  for (int row = hlen; row < nrows - hlen; ++row)
93  for (int col = 0; col < ncols; ++col)
94  opt::at(im2, row, col) = 0;
95 
96  for (int row = 0; row < nrows; ++row)
97  for (int col = hlen; col < ncols - hlen; ++col)
98  opt::at(im2, row, col) = 0;
99 
100  fft = fourier.transformed_image_log_magn<int_u8>(true);
101  io::pgm::save(fft, "fft_trans_cropped.pgm");
102 
103  out = fourier.transform_inv<int_u8>();
104 
105  io::pgm::save(out, "fft_low_pass.pgm");
106 
107  return status;
108 }