2 #include "ScopeHistogram.h"
4 #include "ScopeImage.h"
11 , binsize(static_cast<double>(range-0+1)/_no_of_bins)
12 , hist(_no_of_bins, 0){
17 , binsize(_h.Binsize())
18 , hist(*_h.GetHistConst()) {
23 std::lock_guard<std::mutex> lock(
mutex);
28 std::lock_guard<std::mutex> lock(
mutex);
31 std::fill(std::begin(
hist), std::end(
hist), 0);
33 const uint16_t low(0);
34 const uint16_t high(
range);
42 if ( (val >= low) && (val <= high) )
43 ++(
hist[
static_cast<size_t>(
static_cast<double>(val-low)/
binsize ) ] );
50 std::transform(std::begin(
hist), std::end(
hist), std::begin(
hist), [](uint32_t h) {
51 return static_cast<uint32_t
>(100000 * std::log10(static_cast<double>(h)));
56 std::lock_guard<std::mutex> lock(
mutex);
57 assert(_no_of_bins <= static_cast<uint32_t>(
range-0));
60 hist.resize(_no_of_bins, 0);
64 std::lock_guard<std::mutex> lock(
mutex);
65 return *std::max_element(std::begin(
hist), std::end(
hist));
69 std::lock_guard<std::mutex> lock(
mutex);
70 auto first = std::find_if(std::begin(
hist), std::end(
hist), [&](
const uint32_t& c) {
return c > 0; } );
71 if ( first !=
hist.end() ) {
73 return static_cast<uint16_t
>(
binsize * (first - std::begin(
hist)));
79 std::lock_guard<std::mutex> lock(
mutex);
80 auto last = std::find_if(
hist.rbegin(),
hist.rend(), [&](
const uint32_t& c) {
return c > 0; } );
81 if ( last !=
hist.rend() ) {
83 return static_cast<uint16_t
>(
binsize *
static_cast<double>(
hist.rend() - last) - 1 );
A histogram for a uint16_t image with uint32_t counts.
const uint16_t range
range of uint16 to do histogram of
uint16_t FirstCountPosition() const
double binsize
size of each bin
The BGRA8Pixel struct and various related helpers for color conversions.
This is the include file for standard system include files, or project specific include files that ar...
void ReleaseHistConst() const
uint16_t LastCountPosition() const
std::vector< uint32_t > hist
data vector
const std::vector< uint32_t > * GetHistConst() const
ScopeHistogram(const uint32_t &_no_of_bins=512, const uint16_t &_range=UINT16_MAX)
Initialize to binsize 1 (histogram size is thus UINT16_MAX+1) and zero counts.
const std::vector< T > * GetConstData() const
void Resize(const uint32_t &_no_of_bins)
Resize the histogram to a new number of bins.
void Calculate(ScopeImageU16CPtr const _img, const bool &_loghistogram=false)
Calculate the histogram.
std::mutex mutex
for data protection
Various helper functions and classes for Scope.
Gives RAII safe const access (read-only) to the pixeldata of a ScopeImage.
uint32_t MaxCount() const