 |
NumCpp
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);
79 return static_cast<dtype
>(minValue - 1);
87 const uint32 histSize =
static_cast<uint32>(maxValue - minValue + 1);
91 for (
auto intensity : inImageArray)
98 const double dNumPixels =
static_cast<double>(inImageArray.size());
100 survivalFunction[-1] = 0.0;
101 for (
int32 i = histSize - 1; i > -1; --i)
103 double histValue =
histogram[i] / dNumPixels;
104 survivalFunction[i] = survivalFunction[i + 1] + histValue;
109 uint32 indexHigh = histSize - 1;
110 uint32 index = indexHigh / 2;
112 constexpr
bool keepGoing =
true;
115 const double value = survivalFunction[index];
120 else if (value > inRate)
126 const int32 thresh =
static_cast<int32>(index) + minValue - 1;
129 return static_cast<dtype
>(thresh);
133 return thresh < 0 ? 0 : static_cast<dtype>(thresh);
137 if (indexHigh - indexLow < 2)
139 return static_cast<dtype
>(
static_cast<int32>(indexHigh) + minValue - 1);
142 index = indexLow + (indexHigh - indexLow) / 2;
146 return static_cast<dtype
>(histSize - 1);
value_type item() const
Definition: NdArrayCore.hpp:2950
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:2971
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:3027