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 NDArray<SUM_TYPE, 2> mean() const

Return a copy of the cached mean.

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.

Parameters:

frame – Frame whose shape must exactly match the pedestal.

Throws:

std::runtime_error – if the shape differs.

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.

Parameters:
  • frame – Frame whose shape must exactly match the pedestal.

  • threshold – Per-pixel thresholds with the same shape as the pedestal.

Throws:

std::runtime_error – if either shape differs.

template<typename T>
inline void push(Frame &frame)

Accumulate or exponentially update every pixel from a Frame.

Template Parameters:

T – Actual pixel type stored in frame; this is not runtime-checked.

Parameters:

frame – Frame whose shape must exactly match the pedestal.

Throws:

std::runtime_error – if the shape differs.

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

Private Members

uint32_t m_rows
uint32_t m_cols
uint32_t m_samples
NDArray<uint32_t, 2> m_cur_samples
NDArray<double, 2> m_sum
NDArray<double, 2> m_sum2
NDArray<SUM_TYPE, 2> m_mean