 |
NumCpp
2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
|
Go to the documentation of this file.
43 namespace imageProcessing
56 template<
typename dtype>
61 if (inRate < 0.0 || inRate > 1.0)
72 return static_cast<dtype
>(maxValue);
79 return static_cast<dtype
>(minValue - 1);
85 const auto histSize =
static_cast<uint32>(maxValue - minValue + 1);
89 for (
auto intensity : inImageArray)
96 const auto dNumPixels =
static_cast<double>(inImageArray.size());
98 survivalFunction[-1] = 0.0;
99 for (
int32 i = histSize - 1; i > -1; --i)
101 double histValue =
histogram[i] / dNumPixels;
102 survivalFunction[i] = survivalFunction[i + 1] + histValue;
107 uint32 indexHigh = histSize - 1;
108 uint32 index = indexHigh / 2;
110 constexpr
bool keepGoing =
true;
113 const double value = survivalFunction[index];
118 else if (value > inRate)
124 const int32 thresh =
static_cast<int32>(index) + minValue - 1;
127 return static_cast<dtype
>(thresh);
130 return thresh < 0 ? 0 : static_cast<dtype>(thresh);
133 if (indexHigh - indexLow < 2)
135 return static_cast<dtype
>(
static_cast<int32>(indexHigh) + minValue - 1);
138 index = indexLow + (indexHigh - indexLow) / 2;
142 return static_cast<dtype
>(histSize - 1);
value_type item() const
Definition: NdArrayCore.hpp:2975
std::int32_t int32
Definition: Types.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:57
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2996
std::uint32_t uint32
Definition: Types.hpp:40
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:48
Definition: Coordinate.hpp:44
Holds info about the dtype.
Definition: DtypeInfo.hpp:40
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
NdArray< uint32 > histogram(const NdArray< dtype > &inArray, const NdArray< double > &inBinEdges)
Definition: histogram.hpp:58
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3053