Loading...
Searching...
No Matches
histogram.h
Go to the documentation of this file.
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) 2019, Raspberry Pi Ltd
*
* histogram calculation interface
*/
#pragma once
#include <limits.h>
#include <stdint.h>
#include <type_traits>
#include <vector>
#include <libcamera/base/span.h>
#include <libcamera/base/utils.h>
namespace libcamera {
namespace ipa {
class Histogram
{
public:
Histogram() { cumulative_.push_back(0); }
Histogram(Span<const uint32_t> data);
template<typename Transform,
std::enable_if_t<std::is_invocable_v<Transform, uint32_t>> * = nullptr>
Histogram(Span<const uint32_t> data, Transform transform)
{
cumulative_.resize(data.size() + 1);
cumulative_[0] = 0;
for (const auto &[i, value] : utils::enumerate(data))
cumulative_[i + 1] = cumulative_[i] + transform(value);
}
size_t bins() const { return cumulative_.size() - 1; }
Span<const uint64_t> data() const { return cumulative_; }
uint64_t total() const { return cumulative_[cumulative_.size() - 1]; }
uint64_t cumulativeFrequency(double bin) const;
double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const;
double interQuantileMean(double lowQuantile, double hiQuantile) const;
private:
std::vector<uint64_t> cumulative_;
};
} /* namespace ipa */
} /* namespace libcamera */
libcamera::ipa::Histogram::Histogram
Histogram()
Construct an empty Histogram.
Definition histogram.h:25
libcamera::ipa::Histogram::bins
size_t bins() const
Retrieve the number of bins currently used by the Histogram.
Definition histogram.h:38
libcamera::ipa::Histogram::quantile
double quantile(double q, uint32_t first=0, uint32_t last=UINT_MAX) const
Return the (fractional) bin of the point through the histogram.
Definition histogram.cpp:111
libcamera::ipa::Histogram::cumulativeFrequency
uint64_t cumulativeFrequency(double bin) const
Cumulative frequency up to a (fractional) point in a bin.
Definition histogram.cpp:88
libcamera::ipa::Histogram::data
Span< const uint64_t > data() const
Retrieve the internal data.
Definition histogram.h:39
libcamera::ipa::Histogram::total
uint64_t total() const
Retrieve the total number of values in the data set.
Definition histogram.h:40
libcamera::ipa::Histogram::Histogram
Histogram(Span< const uint32_t > data, Transform transform)
Create a cumulative histogram.
Definition histogram.h:30
libcamera::ipa::Histogram::interQuantileMean
double interQuantileMean(double lowQuantile, double hiQuantile) const
Calculate the mean between two quantiles.
Definition histogram.cpp:149
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition transform.h:14
utils.h
Miscellaneous utility functions.
libcamera::utils::enumerate
auto enumerate(T &iterable)
Wrap an iterable to enumerate index and value in a range-based loop.
Definition utils.h:316