$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
niblack_functor.hh
1 // Copyright (C) 2011 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 #ifndef SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_HH
27 # define SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_HH
28 
32 
33 # include <mln/core/image/image2d.hh>
34 # include <mln/core/alias/neighb2d.hh>
35 # include <mln/extension/fill.hh>
36 
37 # include <scribo/binarization/internal/niblack_formula.hh>
38 
39 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
40 # include <scribo/binarization/internal/local_threshold_debug.hh>
41 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
42 
43 
44 namespace scribo
45 {
46 
47  namespace binarization
48  {
49 
50  namespace internal
51  {
52 
53  using namespace mln;
54 
55 
56  template <typename I>
58  {
59  // Moves in input and output images are made using "step"
60  // pixels. It corresponds to the scale ratio between the input
61  // image and the integral image used to give the statistics
62  // values.
63  enum { step = 1 };
64 
65  niblack_functor(const Image<I>& input, double K);
66 
67  void init();
68 
69  // Run every 4 pixels.
70  void exec(double mean, double stddev);
71 
72  void end_of_row(int);
73 
74  void finalize();
75 
76 
77  const I input;
78  mln_ch_value(I,bool) output;
79 
80  const mln_value(I)* pi;
81  bool* po;
82 
83  double K_;
84 
86 
87  unsigned next_line;
88  };
89 
90 #ifndef MLN_INCLUDE_ONLY
91 
92  template <typename I>
94  double K)
95  : input(exact(input_)),
96  pi(&input(input.domain().pmin())),
97  K_(K)
98  {
99  mln_precondition(exact(input).is_valid());
100  }
101 
102  template <typename I>
103  void
104  niblack_functor<I>::init()
105  {
106  // This initialization MUST be done here since input image
107  // borders may have changed!
108  next_line = 2 * input.border();
109  initialize(output, input);
110  po = &output(output.domain().pmin());
111  }
112 
113  template <typename I>
114  void
115  niblack_functor<I>::exec(double mean, double stddev)
116  {
117  mln_assertion(input.border() == output.border());
118 
119  double th = formula_(mean, stddev, K_);
120 
121  *po++ = (*pi++ <= th);
122  }
123 
124  template <typename I>
125  void
126  niblack_functor<I>::end_of_row(int)
127  {
128  po += next_line;
129  pi += next_line;
130  }
131 
132  template <typename I>
133  void
134  niblack_functor<I>::finalize()
135  {
136  }
137 
138 #endif // ! MLN_INCLUDE_ONLY
139 
140  } // end of namespace scribo::binarization::internal
141 
142  } // end of namespace scribo::binarization
143 
144 } // end of namespace scribo
145 
146 #endif // SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_HH