 |
NumCpp
2.1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
44 namespace imageProcessing
57 template<
typename dtype>
62 if (inRate < 0.0 || inRate > 1.0)
73 return static_cast<dtype
>(maxValue);
80 return static_cast<dtype
>(minValue - 1);
86 const auto histSize =
static_cast<uint32>(maxValue - minValue + 1);
90 for (
auto intensity : inImageArray)
97 const auto dNumPixels =
static_cast<double>(inImageArray.size());
99 survivalFunction[-1] = 0.0;
100 for (
int32 i = histSize - 1; i > -1; --i)
102 double histValue =
histogram[i] / dNumPixels;
103 survivalFunction[i] = survivalFunction[i + 1] + histValue;
108 uint32 indexHigh = histSize - 1;
109 uint32 index = indexHigh / 2;
111 constexpr
bool keepGoing =
true;
114 const double value = survivalFunction[index];
119 else if (value > inRate)
125 const int32 thresh =
static_cast<int32>(index) + minValue - 1;
128 return static_cast<dtype
>(thresh);
131 return thresh < 0 ? 0 : static_cast<dtype>(thresh);
134 if (indexHigh - indexLow < 2)
136 return static_cast<dtype
>(
static_cast<int32>(indexHigh) + minValue - 1);
139 index = indexLow + (indexHigh - indexLow) / 2;
143 return static_cast<dtype
>(histSize - 1);
value_type item() const
Definition: NdArrayCore.hpp:2958
std::int32_t int32
Definition: Types.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:58
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2979
std::uint32_t uint32
Definition: Types.hpp:41
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:49
Definition: Coordinate.hpp:45
Holds info about the dtype.
Definition: DtypeInfo.hpp:41
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
std::pair< NdArray< uint32 >, NdArray< double > > histogram(const NdArray< dtype > &inArray, uint32 inNumBins=10)
Definition: histogram.hpp:57
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3036