SMIL  1.0.4
DLineHistogram.hpp
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _D_LINE_HISTOGRAM_HPP
31 #define _D_LINE_HISTOGRAM_HPP
32 
33 #include "DBaseLineOperations.hpp"
34 
35 namespace smil
36 {
41  template <class T, class T_out = T>
42  struct threshLine : public unaryLineFunctionBase<T, T_out> {
43  T minVal, maxVal;
44  T_out trueVal, falseVal;
45 
46  typedef typename unaryLineFunctionBase<T, T_out>::lineInType lineInType;
47  typedef typename unaryLineFunctionBase<T, T_out>::lineOutType lineOutType;
48 
49  virtual void _exec(const lineInType lIn, const size_t size,
50  lineOutType lOut)
51  {
52  for (size_t i = 0; i < size; i++)
53  lOut[i] = lIn[i] >= minVal && lIn[i] <= maxVal ? trueVal : falseVal;
54  }
55  };
56 
57  template <class Tin, class Tout>
58  struct stretchHistLine : public unaryLineFunctionBase<Tin, Tout> {
59  Tin inOrig;
60  Tout outOrig;
61  double coeff;
62  typedef typename unaryLineFunctionBase<Tin>::lineType lineInType;
63  typedef typename unaryLineFunctionBase<Tout>::lineType lineOutType;
64 
65  virtual void _exec(const lineInType lIn, const size_t size,
66  lineOutType lOut)
67  {
68  double newVal;
69 
70  for (size_t i = 0; i < size; i++) {
71  newVal = double(outOrig) + (double(lIn[i]) - double(inOrig)) * coeff;
72  if (newVal > double(numeric_limits<Tout>::max()))
73  newVal = numeric_limits<Tout>::max();
74  else if (newVal < double(numeric_limits<Tout>::min()))
75  newVal = numeric_limits<Tout>::min();
76  lOut[i] = Tout(round(newVal));
77  }
78  }
79  };
80 
82 
83 } // namespace smil
84 
85 #endif // _D_LINE_HISTOGRAM_HPP
T minVal(const Image< T > &imIn, bool onlyNonZero=false)
minVal() - Min value of an image
Definition: DMeasures.hpp:271
T maxVal(const Image< T > &imIn, bool onlyNonZero=false)
maxVal() - Max value of an image
Definition: DMeasures.hpp:348
Definition: DLineHistogram.hpp:58
Definition: DLineHistogram.hpp:42
Definition: DBaseLineOperations.hpp:46