STIR  6.2.0
thresholding.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2000- 2007, Hammersmith Imanet Ltd
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
11 #ifndef __stir_thresholding_H__
12 #define __stir_thresholding_H__
13 
25 #include <algorithm>
26 
27 START_NAMESPACE_STIR
32 
34 
43 template <typename forw_iterT, typename elemT>
44 inline void
45 threshold_upper_lower(forw_iterT begin, forw_iterT end, const elemT new_min, const elemT new_max)
46 {
47  for (forw_iterT iter = begin; iter != end; ++iter)
48  {
49  if (*iter > new_max)
50  *iter = new_max;
51  else if (new_min > *iter)
52  *iter = new_min;
53  }
54 }
55 
57 
59 template <typename forw_iterT, typename elemT>
60 inline void
61 threshold_upper(forw_iterT begin, forw_iterT end, const elemT new_max)
62 {
63  for (forw_iterT iter = begin; iter != end; ++iter)
64  {
65  if (*iter > new_max)
66  *iter = new_max;
67  }
68 }
69 
71 
73 template <typename forw_iterT, typename elemT>
74 inline void
75 threshold_lower(forw_iterT begin, forw_iterT end, const elemT new_min)
76 {
77  for (forw_iterT iter = begin; iter != end; ++iter)
78  {
79  if (new_min > *iter)
80  *iter = new_min;
81  }
82 }
83 
85 
99 template <typename ForwardIter_t, typename elemT>
100 void
101 threshold_min_to_small_positive_value(ForwardIter_t begin, ForwardIter_t end, const elemT& small_number)
102 {
103  const ForwardIter_t smallest_positive_element_iter = min_positive_element(begin, end);
104 
105  if (smallest_positive_element_iter != end)
106  threshold_lower(begin, end, (*smallest_positive_element_iter) * small_number);
107  else
108  std::fill(begin, end, small_number);
109 }
110 
112 
113 END_NAMESPACE_STIR
114 
115 #endif
Declares the stir::min_positive_element() function.
void threshold_upper_lower(forw_iterT begin, forw_iterT end, const elemT new_min, const elemT new_max)
Threshold a sequence from above and below.
Definition: thresholding.h:45
void threshold_min_to_small_positive_value(ForwardIter_t begin, ForwardIter_t end, const elemT &small_number)
sets non-positive values in the sequence to small positive ones
Definition: thresholding.h:101
ForwardIter_t min_positive_element(ForwardIter_t start, ForwardIter_t end)
Finds where the smallest strictly positive element occurs.
Definition: min_positive_element.h:45
void threshold_upper(forw_iterT begin, forw_iterT end, const elemT new_max)
Threshold a sequence from above.
Definition: thresholding.h:61
void threshold_lower(forw_iterT begin, forw_iterT end, const elemT new_min)
Threshold a sequence from below.
Definition: thresholding.h:75