SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
threshold.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
74 #ifndef SLIP_THRESHOLD_HPP
75 #define SLIP_THRESHOLD_HPP
76 
77 #include <iterator>
78 #include <algorithm>
79 #include <numeric>
80 #include <cassert>
81 #include <cmath>
82 
83 namespace slip
84 {
85 
96  template <typename InType, typename OutType>
97  struct binarize_fun
98  {
99  binarize_fun(const InType& t_value,
100  const OutType& false_value,
101  const OutType& true_value
102  ):
103  t_value_(t_value),false_value_(false_value),true_value_(true_value)
104  {}
105 
106 
107  OutType operator()(const InType& val)
108  {
109  return (val <= t_value_) ? false_value_ : true_value_;
110  }
111 
112  InType t_value_;
113  OutType false_value_;
114  OutType true_value_;
115 
116  };
117 
127  template <typename InType, typename OutType>
129  {
130  threshold_fun(const InType& t_value,
131  const OutType& false_value):
132  t_value_(t_value),false_value_(false_value)
133  {}
134  OutType operator()(const InType& val)
135  {
136  return (val <= t_value_) ? false_value_ : OutType(val);
137  }
138 
139  InType t_value_;
140  OutType false_value_;
141  };
142 
153  template <typename InType, typename OutType>
155  {
156  db_threshold_fun(const InType& min_t_value,const InType& max_t_value,
157  const OutType& false_value):
158  min_t_value_(min_t_value),max_t_value_(max_t_value),false_value_(false_value)
159  {}
160  OutType operator()(const InType& val)
161  {
162  return ((val >= min_t_value_)&&(val <= max_t_value_)) ? false_value_ : OutType(val);
163  }
164 
165  InType min_t_value_;
166  InType max_t_value_;
167  OutType false_value_;
168  };
169 
192  template<typename InputIterator, typename OutputIterator>
193  inline
194  void binarize(InputIterator first,
195  InputIterator last,
196  OutputIterator result,
197  const typename std::iterator_traits<InputIterator>::value_type& t_value,
198  const typename std::iterator_traits<OutputIterator>::value_type& false_value,
199  const typename std::iterator_traits<OutputIterator>::value_type& true_value)
200  {
201  assert(first != last);
202 
204  typename std::iterator_traits<InputIterator>::value_type,
205  typename std::iterator_traits<OutputIterator>::value_type>
206  t_fun(t_value,false_value,true_value);
207 
208  std::transform(first,last,result,t_fun);
209  }
210 
233  template<typename InputIterator, typename OutputIterator>
234  inline
235  void threshold(InputIterator first,
236  InputIterator last,
237  OutputIterator result,
238  const typename std::iterator_traits<InputIterator>::value_type& t_value,
239  const typename std::iterator_traits<OutputIterator>::value_type& false_value)
240  {
241  assert(first != last);
242 
244  typename std::iterator_traits<InputIterator>::value_type,
245  typename std::iterator_traits<OutputIterator>::value_type>
246  t_fun(t_value,false_value);
247 
248  std::transform(first,last,result,t_fun);
249  }
250 
274  template<typename InputIterator, typename OutputIterator>
275  inline
276  void db_threshold(InputIterator first,
277  InputIterator last,
278  OutputIterator result,
279  const typename std::iterator_traits<InputIterator>::value_type& min_t_value,
280  const typename std::iterator_traits<InputIterator>::value_type& max_t_value,
281  const typename std::iterator_traits<OutputIterator>::value_type& false_value)
282  {
283  assert(first != last);
284 
286  typename std::iterator_traits<InputIterator>::value_type,
287  typename std::iterator_traits<OutputIterator>::value_type>
288  t_fun(min_t_value,max_t_value,false_value);
289 
290  std::transform(first,last,result,t_fun);
291 }
292 
293 
337  template<typename InputIterator1,
338  typename RandomAccessIterator1,
339  typename RandomAccessIterator2,
340  typename OutputIterator>
341  void multi_threshold(InputIterator1 first,
342  InputIterator1 last,
343  RandomAccessIterator1 first_th,
344  RandomAccessIterator1 last_th,
345  RandomAccessIterator2 first_level,
346  RandomAccessIterator2 last_level,
347  OutputIterator result_first,
348  OutputIterator result_last)
349  {
350 
351  assert((last_th-first_th) == (last_level-first_level));
352  assert((last - first) == (result_last - result_first));
353 
354  RandomAccessIterator1 tmp_t = first_th;
355  RandomAccessIterator2 tmp_l = first_level;
356 
357  for(;first!=last; ++first, ++result_first)
358  {
359  for ( ; first_th != last_th ; ++first_th, ++first_level)
360  {
361  if (*first <= *tmp_t)
362  {
363  *result_first = *tmp_l;
364  }
365 
366  else if((*(first_th-1) < *first) && (*first <= *first_th))
367  {
368  *result_first = *first_level;
369  }
370  else if( *first > *(last_th - 1))
371  {
372  *result_first = *(last_level - 1);
373  }
374  }
375  first_th = tmp_t;
376  first_level = tmp_l;
377  }
378  }
379 
380 
381 }//slip::
382 
383 
384 #endif //SLIP_THRESHOLD_HPP
OutType operator()(const InType &val)
Definition: threshold.hpp:134
threshold_fun(const InType &t_value, const OutType &false_value)
Definition: threshold.hpp:130
void db_threshold(InputIterator first, InputIterator last, OutputIterator result, const typename std::iterator_traits< InputIterator >::value_type &min_t_value, const typename std::iterator_traits< InputIterator >::value_type &max_t_value, const typename std::iterator_traits< OutputIterator >::value_type &false_value)
double-threshold algorithm
Definition: threshold.hpp:276
Functor object used to double-threshold a value.
Definition: threshold.hpp:154
void threshold(InputIterator first, InputIterator last, OutputIterator result, const typename std::iterator_traits< InputIterator >::value_type &t_value, const typename std::iterator_traits< OutputIterator >::value_type &false_value)
threshold algorithm
Definition: threshold.hpp:235
Functor object used to binarize a value.
Definition: threshold.hpp:97
Functor object used to threshold a value.
Definition: threshold.hpp:128
db_threshold_fun(const InType &min_t_value, const InType &max_t_value, const OutType &false_value)
Definition: threshold.hpp:156
OutType operator()(const InType &val)
Definition: threshold.hpp:160
binarize_fun(const InType &t_value, const OutType &false_value, const OutType &true_value)
Definition: threshold.hpp:99
void multi_threshold(InputIterator1 first, InputIterator1 last, RandomAccessIterator1 first_th, RandomAccessIterator1 last_th, RandomAccessIterator2 first_level, RandomAccessIterator2 last_level, OutputIterator result_first, OutputIterator result_last)
multi_threshold algorithm It is equivalent to a quantification J[i] = Level[i] if T[i-1] < I[i] <= T[...
Definition: threshold.hpp:341
void binarize(InputIterator first, InputIterator last, OutputIterator result, const typename std::iterator_traits< InputIterator >::value_type &t_value, const typename std::iterator_traits< OutputIterator >::value_type &false_value, const typename std::iterator_traits< OutputIterator >::value_type &true_value)
binarize algorithm
Definition: threshold.hpp:194
OutType operator()(const InType &val)
Definition: threshold.hpp:107