STIR 6.4.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__
23
25#include <algorithm>
26
27START_NAMESPACE_STIR
32
34
43template <typename forw_iterT, typename elemT>
44inline void
45threshold_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
59template <typename forw_iterT, typename elemT>
60inline void
61threshold_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
73template <typename forw_iterT, typename elemT>
74inline void
75threshold_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
99template <typename ForwardIter_t, typename elemT>
100void
101threshold_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
113END_NAMESPACE_STIR
114
115#endif
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
Declares the stir::min_positive_element() function.
void threshold_upper(forw_iterT begin, forw_iterT end, const elemT new_max)
Threshold a sequence from above.
Definition thresholding.h:61
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
void threshold_lower(forw_iterT begin, forw_iterT end, const elemT new_min)
Threshold a sequence from below.
Definition thresholding.h:75
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