53 template<
typename dtype>
58 if (inRate < 0. || inRate > 1.)
69 return static_cast<dtype
>(maxValue);
76 return static_cast<dtype
>(minValue - 1);
82 const auto histSize =
static_cast<uint32>(maxValue - minValue + 1);
86 for (
auto intensity : inImageArray)
93 const auto dNumPixels =
static_cast<double>(inImageArray.
size());
95 survivalFunction[-1] = 0.;
96 for (
int32 i = histSize - 1; i > -1; --i)
98 double histValue =
histogram[i] / dNumPixels;
99 survivalFunction[i] = survivalFunction[i + 1] + histValue;
104 uint32 indexHigh = histSize - 1;
105 uint32 index = indexHigh / 2;
107 constexpr bool keepGoing =
true;
110 const double value = survivalFunction[index];
115 else if (value > inRate)
121 const int32 thresh =
static_cast<int32>(index) + minValue - 1;
124 return static_cast<dtype
>(thresh);
127 return thresh < 0 ? 0 : static_cast<dtype>(thresh);
130 if (indexHigh - indexLow < 2)
132 return static_cast<dtype
>(
static_cast<int32>(indexHigh) + minValue - 1);
135 index = indexLow + (indexHigh - indexLow) / 2;
139 return static_cast<dtype
>(histSize - 1);
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds info about the dtype.
Definition: DtypeInfo.hpp:41
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
self_type max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3041
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
value_type item() const
Definition: NdArrayCore.hpp:3022
self_type min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3085
Definition: applyThreshold.hpp:34
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:54
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:48
std::int32_t int32
Definition: Types.hpp:36
NdArray< uint32 > histogram(const NdArray< dtype > &inArray, const NdArray< double > &inBinEdges)
Definition: histogram.hpp:57
std::uint32_t uint32
Definition: Types.hpp:40