43 namespace imageProcessing
55 template<
typename dtype>
60 if (inRate < 0. || inRate > 1.)
71 return static_cast<dtype
>(maxValue);
78 return static_cast<dtype
>(minValue - 1);
84 const auto histSize =
static_cast<uint32>(maxValue - minValue + 1);
88 for (
auto intensity : inImageArray)
95 const auto dNumPixels =
static_cast<double>(inImageArray.
size());
97 survivalFunction[-1] = 0.;
98 for (
int32 i = histSize - 1; i > -1; --i)
100 double histValue =
histogram[i] / dNumPixels;
101 survivalFunction[i] = survivalFunction[i + 1] + histValue;
106 uint32 indexHigh = histSize - 1;
107 uint32 index = indexHigh / 2;
109 constexpr
bool keepGoing =
true;
112 const double value = survivalFunction[index];
117 else if (value > inRate)
123 const int32 thresh =
static_cast<int32>(index) + minValue - 1;
126 return static_cast<dtype
>(thresh);
129 return thresh < 0 ? 0 : static_cast<dtype>(thresh);
132 if (indexHigh - indexLow < 2)
134 return static_cast<dtype
>(
static_cast<int32>(indexHigh) + minValue - 1);
137 index = indexLow + (indexHigh - indexLow) / 2;
141 return static_cast<dtype
>(histSize - 1);
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
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:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4105
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2872
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2828
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:56
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
Definition: Coordinate.hpp:45
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