SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamic.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 
68 
69 #ifndef DYNAMIC_HPP
70 #define DYNAMIC_HPP
71 
78 #include <algorithm>
79 #include <cassert>
80 #include <cmath>
81 #include "stl_algo_ext.hpp"
82 #include "statistics.hpp"
83 
84 namespace slip
85 {
86 
108 {
112 };
113 
114 
115 
128  template <typename InType, typename OutType>
130  {
131  range_fun_interab(const InType& in_min,
132  const InType& in_max,
133  const OutType& out_min,
134  const OutType& out_max):
135  in_min_(in_min),in_max_(in_max),out_min_(out_min),out_max_(out_max)
136  {}
137 
138  OutType operator()(const InType& val)
139  {
140  double d = in_max_ - in_min_;
141  double a = out_max_ - out_min_;
142  double b = (in_max_ * out_min_) - (in_min_ * out_max_);
143  return OutType((a * val + b) / d);
144  }
145 
146  InType in_min_;
147  InType in_max_;
148  OutType out_min_;
149  OutType out_max_;
150  };
151 
152 
163  template <typename InType, typename Real>
165  {
166  range_fun_inter01(const InType& in_min,
167  const InType& in_max):
168  in_min_(in_min),in_max_(in_max)
169  {}
170 
171  Real operator()(const InType& val)
172  {
173  Real d = Real(in_max_ - in_min_);
174  return Real(val - in_min_) / d;
175  }
176  InType in_min_;
177  InType in_max_;
178  };
179 
180 
191  template <typename InType, typename OutType>
193  {
194  range_fun_inter0255(const InType& in_min,
195  const InType& in_max):
196  in_min_(in_min),in_max_(in_max)
197  {}
198 
199  OutType operator()(const InType& val)
200  {
201  return OutType(255 * ((val - in_min_) / (in_max_ - in_min_)));
202  }
203  InType in_min_;
204  InType in_max_;
205  };
206 
218  template <typename InType, typename OutType>
220  {
221  range_fun_inter0b(const InType& in_min,
222  const InType& in_max,
223  const OutType& out_max):
224  in_min_(in_min),in_max_(in_max),out_max_(out_max)
225  {}
226 
227  OutType operator()(const InType& val)
228  {
229  double d = in_max_ - in_min_;
230  return OutType(out_max_ * (double(val) - in_min_) / d);
231  }
232  InType in_min_;
233  InType in_max_;
234  OutType out_max_;
235  };
236 
248  template <typename InType, typename Real, typename RealOut>
250  {
251  range_fun_normal(const Real& in_mean,
252  const Real& in_sigma):
253  in_mean_(in_mean),in_sigma_(in_sigma)
254  {}
255 
256  RealOut operator()(const InType& val)
257  {
258  double d = (double(val) - double(in_mean_)) / double(in_sigma_);
259  return RealOut(d);
260  }
261  Real in_mean_;
262  Real in_sigma_;
263  };
264 
265 
276  template <typename InType, typename Real>
278  {
279  range_fun_sigmoide(const Real& in_mean,
280  const Real& in_sigma):
281  in_mean_(in_mean),in_sigma_(in_sigma)
282  {}
283 
284  Real operator()(const InType& val)
285  {
286  return 1.0 / (1.0 + std::exp((in_mean_ - val) / in_sigma_ ));
287  }
288  Real in_mean_;
289  Real in_sigma_;
290  };
291 
303  template <typename InType, typename Real, typename OutType>
305  {
306  range_fun_sigmoideb(const Real& in_mean,
307  const Real& in_sigma,
308  const OutType& b):
309  in_mean_(in_mean),in_sigma_(in_sigma),b_(b)
310  {}
311 
312  OutType operator()(const InType& val)
313  {
314  return OutType(b_ / (1.0 + std::exp((in_mean_ - val) / in_sigma_)));
315  }
316  Real in_mean_;
317  Real in_sigma_;
318  OutType b_;
319  };
320 
321 
322 
353  template<typename InputIterator,
354  typename OutputIterator,
355  typename UnaryOperation>
356  inline
357  void change_dynamic(InputIterator first,
358  InputIterator last,
359  OutputIterator result,
360  UnaryOperation dynamic_fun)
361  {
362  std::transform(first,last,result,dynamic_fun);
363  }
364 
401 template<typename InputIterator,
402  typename OutputIterator,
403  typename MaskIterator,
404  typename UnaryOperation>
405 inline
406  void change_dynamic_mask(InputIterator first,
407  InputIterator last,
408  MaskIterator mask_first,
409  OutputIterator result,
410  UnaryOperation dynamic_fun,
411  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
412  {
413  slip::transform_mask_un(first,last,mask_first,result,dynamic_fun,value);
414  }
460 template<typename InputIterator,
461  typename OutputIterator,
462  typename UnaryOperation,typename Predicate>
463 inline
464  void change_dynamic_if(InputIterator first,
465  InputIterator last,
466  OutputIterator result,
467  Predicate pred,
468  UnaryOperation dynamic_fun)
469  {
470  slip::transform_if(first,last,result,dynamic_fun,pred);
471  }
472 
492  template<typename InputIterator,
493  typename OutputIterator>
494  inline
495  void change_dynamic_01(InputIterator first,
496  InputIterator last,
497  OutputIterator result,
499 
500  {
501  typedef typename std::iterator_traits<InputIterator>::value_type in_type;
502  typedef typename std::iterator_traits<OutputIterator>::value_type out_type;
503 
504  switch (fun)
505  {
506  case AFFINE_FUNCTION:
507  slip::change_dynamic(first,last,
508  result,
510  (*std::min_element(first,last),
511  *std::max_element(first,last)));
512  break;
513  case SIGMOID_FUNCTION:
514  {
515  double mean = slip::mean<double>(first,last);
516  double sigma = slip::std_dev<double>(first,last,mean);
517  slip::change_dynamic(first,last,
518  result,
520  (mean,sigma));
521 
522  break;
523  }
524  default :
525  slip::change_dynamic(first,last,
526  result,
528  (*std::min_element(first,last),
529  *std::max_element(first,last)));
530  }
531  }
532 
533 
534 
535 }//slip::
536 
537 
538 #endif //DYNAMIC_HPP
Real operator()(const InType &val)
Definition: dynamic.hpp:171
OutType operator()(const InType &val)
Definition: dynamic.hpp:199
range_fun_sigmoide(const Real &in_mean, const Real &in_sigma)
Definition: dynamic.hpp:279
range_fun_inter01(const InType &in_min, const InType &in_max)
Definition: dynamic.hpp:166
void change_dynamic(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation dynamic_fun)
Changes the dynamic of a container.
Definition: dynamic.hpp:357
Functor object uses to change the range of container into [0,b].
Definition: dynamic.hpp:219
_OutputIterator transform_if(_InputIterator first, _InputIterator last, _OutputIterator result, _UnaryOperation unary_op, _Predicate pred)
Perform an operation on a sequence according to a Predicate.
RealOut operator()(const InType &val)
Definition: dynamic.hpp:256
range_fun_inter0b(const InType &in_min, const InType &in_max, const OutType &out_max)
Definition: dynamic.hpp:221
HyperVolume< T > exp(const HyperVolume< T > &M)
Functor object uses to change the range of container applying sigmoide distribution between [0...
Definition: dynamic.hpp:304
void change_dynamic_01(InputIterator first, InputIterator last, OutputIterator result, slip::NORMALIZATION_FUNCTION fun)
Changes the dynamic of a container.
Definition: dynamic.hpp:495
OutType operator()(const InType &val)
Definition: dynamic.hpp:312
OutType operator()(const InType &val)
Definition: dynamic.hpp:138
range_fun_interab(const InType &in_min, const InType &in_max, const OutType &out_min, const OutType &out_max)
Definition: dynamic.hpp:131
void change_dynamic_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, UnaryOperation dynamic_fun)
Changes the dynamic of a container according to a predicate.
Definition: dynamic.hpp:464
Provides some statistics algorithms.
range_fun_sigmoideb(const Real &in_mean, const Real &in_sigma, const OutType &b)
Definition: dynamic.hpp:306
Functor object uses to change the range of container into [0,255].
Definition: dynamic.hpp:192
_OutputIterator transform_mask_un(_InputIterator first, _InputIterator last, _MaskIterator mask_first, _OutputIterator result, _UnaryOperation unary_op, typename std::iterator_traits< _MaskIterator >::value_type value=typename std::iterator_traits< _MaskIterator >::value_type(1))
Perform an operation on a sequence according to a mask sequence.
Value_T mean(InputIterator first, InputIterator last)
Computes the mean value of a range .
Definition: statistics.hpp:314
Provides some extension to STL algorithms.
range_fun_inter0255(const InType &in_min, const InType &in_max)
Definition: dynamic.hpp:194
Functor object uses to change the range of container according to an affine transformation.
Definition: dynamic.hpp:129
Functor object uses to change the range of container into [0,1].
Definition: dynamic.hpp:164
void change_dynamic_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, UnaryOperation dynamic_fun, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Changes the dynamic of a container according to a mask sequence.
Definition: dynamic.hpp:406
NORMALIZATION_FUNCTION
Choose between different border treatment modes for convolution algorithms.
Definition: dynamic.hpp:107
range_fun_normal(const Real &in_mean, const Real &in_sigma)
Definition: dynamic.hpp:251
Functor object uses to change the range of container applying normal distribution.
Definition: dynamic.hpp:249
Functor object uses to change the range of container applying sigmoide distribution.
Definition: dynamic.hpp:277
Real operator()(const InType &val)
Definition: dynamic.hpp:284
OutType operator()(const InType &val)
Definition: dynamic.hpp:227