$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compute_sub_domains.hh
1 // Copyright (C) 2011, 2013 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 SCRIBO_UTIL_COMPUTE_SUB_DOMAINS_HH
28 # define SCRIBO_UTIL_COMPUTE_SUB_DOMAINS_HH
29 
33 
34 # include <mln/core/image/image2d.hh>
35 # include <mln/util/couple.hh>
36 
37 namespace scribo
38 {
39 
40  namespace util
41  {
42 
43  using namespace mln;
44 
45  template <typename I>
47  compute_sub_domains(const Image<I>& ima, unsigned n_scales, unsigned s);
48 
49 
50 # ifndef MLN_INCLUDE_ONLY
51 
52  namespace internal
53  {
54 
55  inline
56  unsigned sub(unsigned nbr, unsigned down_scaling)
57  {
58  return (nbr + down_scaling - 1) / down_scaling;
59  }
60 
61  } // end of namespace scribo::util::internal
62 
63 
64 
65  template <typename I>
67  compute_sub_domains(const Image<I>& ima_, unsigned n_scales, unsigned s)
68  {
69  mln_trace("scribo::util::compute_sub_domains");
70 
71  const I& ima = exact(ima_);
72  mln_precondition(ima.is_valid());
73 
75 
76  n(1) = mln::make::couple(ima.nrows(), ima.ncols());
77  n(2) = mln::make::couple(internal::sub(n(1).first(), s),
78  internal::sub(n(1).second(), s));
79  for (unsigned i = 3; i <= n_scales + 1; ++i)
80  n(i) = mln::make::couple(internal::sub(n(i - 1).first(), 2),
81  internal::sub(n(i - 1).second(), 2));
82 
83 
85  out(0) = mln::make::couple(mln::make::box2d(1,1), 1u);
86  out(1) = mln::make::couple(mln::make::box2d(ima.nrows(),
87  ima.ncols()), 2u);
88  out(n_scales + 1) = mln::make::couple(
89  mln::make::box2d(n(n_scales + 1).first(),
90  n(n_scales + 1).second()), 1u);
91 
92  for (unsigned i = n_scales; i > 1; --i)
93  out(i) = mln::make::couple(
94  mln::make::box2d(2 * out(i + 1).first().nrows(),
95  2 * out(i + 1).first().ncols()),
96  2 * out(i + 1).second());
97 
98  out(1).second() = std::max(out(2).first().ncols() * s - ima.ncols(),
99  out(2).first().nrows() * s - ima.nrows());
100 
101  return out;
102  }
103 
104 # endif // ! MLN_INCLUDE_ONLY
105 
106  } // end of namespace scribo::util
107 
108 } // end of namespace scribo
109 
110 #endif // ! SCRIBO_UTIL_COMPUTE_SUB_DOMAINS_HH
111