Pedestal¶
-
template<typename SUM_TYPE = double>
class Pedestal¶ Maintain per-pixel mean and population standard deviation.
Each pixel accumulates its first n_samples values. Subsequent pushes update the exponential moving average with a smoothing factor of 1 / n_samples. Statistics are available during initialization and are zero for empty pixels. Internal moments and the private variance intermediate use double precision.
- Template Parameters:
SUM_TYPE – Type returned for the mean and standard deviation.
Public Functions
-
inline Pedestal(uint32_t rows, uint32_t cols, uint32_t n_samples = 1000)¶
Construct an empty pedestal with zero mean and standard deviation.
- Parameters:
rows – Number of image rows.
cols – Number of image columns.
n_samples – Number of initialization samples per pixel and reciprocal of the weight assigned to each subsequent value.
- Throws:
std::runtime_error – if rows, cols, or n_samples is zero.
-
~Pedestal() = default¶
-
inline NDView<const SUM_TYPE, 2> view() const¶
Return a non-owning view of the cached mean.
Note
The caller must treat the data as read-only and must not retain the view after this object is destroyed, moved, or assigned.
-
inline SUM_TYPE mean(const uint32_t row, const uint32_t col) const¶
Return the cached mean at (row, col), or zero for an empty pixel.
- Pre:
row and col are valid pixel indices.
-
inline SUM_TYPE std(const uint32_t row, const uint32_t col) const¶
Calculate the population standard deviation at (row, col).
Note
Variance is normalized by the pixel’s current sample count. Empty pixels return zero, and negative variance from roundoff is clamped to zero.
- Pre:
row and col are valid pixel indices.
-
inline NDArray<SUM_TYPE, 2> std() const¶
Calculate and return the population standard deviation of every pixel. Empty pixels return zero.
-
inline void clear()¶
Zero the moments, cached mean, and sample counts of every pixel.
-
inline void clear(const uint32_t row, const uint32_t col)¶
Zero the moments, cached mean, and sample count at (row, col).
- Pre:
row and col are valid pixel indices.
-
template<typename T>
inline void push(NDView<T, 2> frame)¶ Accumulate or exponentially update every pixel and its cached mean.
-
template<typename T>
inline void push_with_threshold(const NDView<T, 2> frame, const NDView<SUM_TYPE, 2> threshold)¶ Push only pixels whose absolute difference from the cached mean is strictly less than their threshold.
Note
Rejected pixels keep their statistics and sample counts unchanged.
-
template<typename T>
inline void push(Frame &frame)¶ Accumulate or exponentially update every pixel from a Frame.
-
inline uint32_t rows() const¶
Return the number of image rows.
-
inline uint32_t cols() const¶
Return the number of image columns.
-
inline uint32_t n_samples() const¶
Return the initialization sample count per pixel and steady-state update-weight denominator.
-
inline NDArray<uint32_t, 2> cur_samples() const¶
Return a copy of the per-pixel initialization sample counts.
Note
Each count is in [0, n_samples] and does not change during steady-state pushes. Thresholded pushes can leave counts unequal.
-
template<typename T>
inline void push(const uint32_t row, const uint32_t col, const T val_)¶ Accumulate or exponentially update one pixel and its cached mean.
- Parameters:
row – Pixel row.
col – Pixel column.
val_ – New pixel value, with weight 1 / n_samples after initialization.
- Pre:
row and col are valid pixel indices.
Private Functions
-
inline double variance(const uint32_t row, const uint32_t col) const¶