libcamera v0.6.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
histogram.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2/*
3 * Copyright (C) 2019, Raspberry Pi Ltd
4 *
5 * histogram calculation interface
6 */
7
8#pragma once
9
10#include <limits.h>
11#include <stdint.h>
12#include <type_traits>
13#include <vector>
14
15#include <libcamera/base/span.h>
16#include <libcamera/base/utils.h>
17
18 namespace libcamera {
19
20 namespace ipa {
21
22 class Histogram
23{
24 public:
25 Histogram() { cumulative_.push_back(0); }
26 Histogram(Span<const uint32_t> data);
27
28 template<typename Transform,
29 std::enable_if_t<std::is_invocable_v<Transform, uint32_t>> * = nullptr>
30 Histogram(Span<const uint32_t> data, Transform transform)
31 {
32 cumulative_.resize(data.size() + 1);
33 cumulative_[0] = 0;
34 for (const auto &[i, value] : utils::enumerate(data))
35 cumulative_[i + 1] = cumulative_[i] + transform(value);
36 }
37
38 size_t bins() const { return cumulative_.size() - 1; }
39 Span<const uint64_t> data() const { return cumulative_; }
40 uint64_t total() const { return cumulative_[cumulative_.size() - 1]; }
41 uint64_t cumulativeFrequency(double bin) const;
42 double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const;
43 double interQuantileMean(double lowQuantile, double hiQuantile) const;
44
45 private:
46 std::vector<uint64_t> cumulative_;
47};
48
49} /* namespace ipa */
50
51} /* 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:318