blob: 6fd641683694f2b815bd21865550e97bde5f83b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/* 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; }
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 */
|